buffalo: Reproducible problem with app.Mount (just Copy & Paste).

If you copy & paste the code below you can reproduce the problem with app.Mount:

actions/app.go:

package actions

import (
	"fmt"
	"github.com/gobuffalo/buffalo"
	"github.com/gobuffalo/envy"
	"github.com/gorilla/mux"
	"net/http"
)

var ENV = envy.Get("GO_ENV", "development")
var app *buffalo.App

func funcTest(res http.ResponseWriter, req *http.Request) {
	fmt.Fprintf(res, "%s - HELLOOOOOOOOOOOOO - %s", req.Method, req.URL.String())
}

func muxer() http.Handler {
	r := mux.NewRouter()
	r.HandleFunc("/foo", funcTest).Methods("GET")
	r.HandleFunc("/bar", funcTest).Methods("POST")
	r.HandleFunc("/baz/baz", funcTest).Methods("DELETE")
	return r
}

func App() *buffalo.App {
	if app == nil {
		app = buffalo.New(buffalo.Options{
			Env:         ENV,
			SessionName: "_mytestapp_session",
		})

		app.Mount("/admin", muxer())

		app.Mount("/strip", http.StripPrefix("/strip", muxer()))

		app.ANY("/test/{path:.+}", buffalo.WrapHandler(http.StripPrefix("/test", muxer())))

		app.GET("/one", buffalo.WrapHandlerFunc(funcTest))

		app.GET("/", HomeHandler)

		app.ServeFiles("/", assetsBox)
	}

	return app
}

I think there is a problem with app.Mount in Buffalo.

Fixing this we can close this and other 2 related issues I think:

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (17 by maintainers)

Most upvoted comments

I’m sorry, I can’t write this code for you. I’m supporting this in my free time. It’s sunday morning.

app.Mount(somehandlerthatstripsthelastslash(youmux)) On Dec 16, 2018, 8:57 AM -0500, frederikhors notifications@github.com, wrote:

You can either strip the / before you send it Auth boss using a handler. What does this phrase mean? I’m using app.Mount(“/auth”, Ab.Config.Core.Router) and Ab.Config.Core.Router comes from authboss backbox. I just wanna use Buffalo to mount everything (like Rails), not a separate mux. Why LooseSlash option removed? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.