I am developping a web service in Go which delegates its UI to a vue.js
website packaged with webpack
.
My Go service is responsible for hosting the UI and a REST API that the UI use.
In development mode, I would want to benefit from the vue.js
and webpack
tooling (inotify-based auto-reload for instance) so I added a switch in my Go program that does this:
var handler http.Handler
if isDevelopment {
// url below points to the webpack standalone
// development server, at http://localhost:8080.
proxy := httputil.NewSingleHostReverseProxy(url)
proxy.FlushInterval = time.Millisecond * 100
handler = proxy
} else {
handler = http.FileServer(http.Dir("www"))
}
So basically, in development mode I can launch webpack's development server (with npm run dev
) and my Go program delegates all the UI requests to it.
This works wonders except that after a couple of seconds, Chrome complains that:
GET http://localhost:9999/__webpack_hmr net::ERR_INCOMPLETE_CHUNKED_ENCODING
The auto-refresh stops working for a while and eventually comes back, but its way slower than if I directly connect to webpack's standalone server.
I think could track down the problem in Go's httputil.ReverseProxy
and I believe it doesn't have any specific code to handle event sources properly.
Is this a know issue ? Is there anything I could do to make my Go reverse proxy event source aware/compatible ?