Add documentation for using mux to serve a SPA#493
Conversation
| "github.com/gorilla/mux" | ||
| ) | ||
|
|
||
| type spaHandler struct { |
There was a problem hiding this comment.
It might be more accessible to make this middleware or more self-contained http.HandlerFunc?
e.g.
func ServeJavaScriptApp(staticDir string, entryPoint string) http.Handler {
// fn := func(w http.ResponseWriter, r *http.Request) { ... }
//
// return http.HandlerFunc(fn)
}... and then:
serveJSHandler := ServeJavaScriptApp("./dist", "index.html")
r.Use(staticHandler)
r.PathPrefix("/").Handler(serveJSHandler)Not tied to this - just might be more accessible to a newcomer? Open to feedback on this.
There was a problem hiding this comment.
Hmm. I can see how a http.HandlerFunc might be easier for a beginner than a type implementing http.Handler, however I think the overhead of the closure might outweigh that. Overall I think both are about as easy for a beginner to understand (also open to feedback of course 😄).
There was a problem hiding this comment.
So, thinking on this: should we add a “ServeStatic” or similar handler as a built-in? This has come up a few times.
elithrar
left a comment
There was a problem hiding this comment.
Options:
a) leave this as docs
b) add a new built-in handler
|
I think implementing a built-in handler in |
|
Let me know if you think it still makes sense to add a built-in handler with the docs improvements and I'll implement that 👍 |
|
Let's leave it as-is for now, @fharding1 - we can revisit later. |
|
(Thanks for working on this, too!) |
|
Np, thank you! |
Fixes #464
Summary of Changes
Testing
I ran create-react-app, made a prod build, copied the build directory, and tested this out. Seems to work great.