-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, thinking on this: should we add a “ServeStatic” or similar handler as a built-in? This has come up a few times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.