From 6eb55f2d1caf1bd2977eb7a5d325457f7f3ce975 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Thu, 21 Dec 2017 11:45:33 -0500 Subject: [PATCH] StrictSlash should be customizable fixes #810 --- app.go | 2 +- options.go | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app.go b/app.go index 226f53687..c54c09f11 100644 --- a/app.go +++ b/app.go @@ -162,7 +162,7 @@ func New(opts Options) *App { 404: defaultErrorHandler, 500: defaultErrorHandler, }, - router: mux.NewRouter().StrictSlash(true), + router: mux.NewRouter().StrictSlash(!opts.LooseSlash), moot: &sync.Mutex{}, routes: RouteList{}, children: []*App{}, diff --git a/options.go b/options.go index 8a257aa19..d9bae0cd8 100644 --- a/options.go +++ b/options.go @@ -22,15 +22,21 @@ type Options struct { // Addr is the bind address provided to http.Server. Default is "127.0.0.1:3000" // Can be set using ENV vars "ADDR" and "PORT". Addr string + // Host that this application will be available at. Default is "http://127.0.0.1:[$PORT|3000]". + Host string + // Env is the "environment" in which the App is running. Default is "development". Env string + // LogLevel defaults to "debug". LogLevel string // Logger to be used with the application. A default one is provided. Logger Logger + // MethodOverride allows for changing of the request method type. See the default // implementation at buffalo.MethodOverride MethodOverride http.HandlerFunc + // SessionStore is the `github.com/gorilla/sessions` store used to back // the session. It defaults to use a cookie store and the ENV variable // `SESSION_SECRET`. @@ -38,8 +44,7 @@ type Options struct { // SessionName is the name of the session cookie that is set. This defaults // to "_buffalo_session". SessionName string - // Host that this application will be available at. Default is "http://127.0.0.1:[$PORT|3000]". - Host string + // Worker implements the Worker interface and can process tasks in the background. // Default is "github.com/gobuffalo/worker.Simple. Worker worker.Worker @@ -55,8 +60,13 @@ type Options struct { PreWares []PreWare Context context.Context - cancel context.CancelFunc - Prefix string + + // LooseSlash defines the trailing slash behavior for new routes. The initial value is false. + // This is the opposite of http://www.gorillatoolkit.org/pkg/mux#Router.StrictSlash + LooseSlash bool + + cancel context.CancelFunc + Prefix string } // PreWare takes an http.Handler and returns and http.Handler