web
web copied to clipboard
Expose mainServer in the fashion of http.DefaultServeMux
At the moment, if you've written a code like
web.Get("/", handler)
web.Get("/somethingelse", anotherHandler)
// etc.
There is no way (AFAIK) to get the http.Handler behind this (in case you'd like to wrap it in some middleware, etc.). All you can do is create a new Server
and then rewrite the code to use it (rather than the module-level functions that work on the main server).
I don't think there would be any trouble with exposing mainServer
publicly, kind of like http.DefaultServeMux
is exposed (feel free to correct me). If you don't care about an extra variable lying around, then it's a one-line fix:
var MainServer = mainServer
(otherwise you'd have to s/mainServer/MainServer
everywhere).
I'd like to hear some feedback on this. Would anyone else find this useful? Is this more complex than I think and there'd be some weird problems?
Connected to #214 - if it was possible to access the handler directly, cors could be handled by e.g. https://github.com/rs/cors :)