Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.

Commit 27e5983

Browse files
author
Stephen Gutekanst
committed
correct SPA page serving in release builds
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
1 parent dc78d5f commit 27e5983

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

cmd/doctree/serve.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,19 @@ func frontendHandler() http.Handler {
138138
}
139139

140140
// Server assets that are embedded into Go binary.
141-
return http.FileServer(http.FS(frontend.EmbeddedFS()))
141+
fs := http.FS(frontend.EmbeddedFS())
142+
fileServer := http.FileServer(fs)
143+
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
144+
// If there is not a file present, then this request is likely for a page like
145+
// "/github.com/sourcegraph/sourcegraph" and we should still serve the SPA. Change the
146+
// request path to "/" prior to serving so index.html is what gets served.
147+
f, err := fs.Open(req.URL.Path)
148+
if err != nil {
149+
req.URL.Path = "/"
150+
} else {
151+
f.Close()
152+
}
153+
154+
fileServer.ServeHTTP(w, req)
155+
})
142156
}

0 commit comments

Comments
 (0)