@@ -313,6 +313,12 @@ func AuthenticationMiddleware(next http.Handler) http.Handler {
313313
314314// FileServerMiddleware serves files from the static folder
315315func FileServerMiddleware (next http.Handler ) http.Handler {
316+ buildFs , err := fs .Sub (portal_ui .GetStaticAssets (), "build" )
317+ if err != nil {
318+ panic (err )
319+ }
320+ spaFileHandler := wrapHandlerSinglePageApplication (requestBounce (http .FileServer (http .FS (buildFs ))))
321+
316322 return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
317323 w .Header ().Set ("Server" , globalAppName ) // do not add version information
318324 switch {
@@ -321,11 +327,7 @@ func FileServerMiddleware(next http.Handler) http.Handler {
321327 case strings .HasPrefix (r .URL .Path , "/api" ):
322328 next .ServeHTTP (w , r )
323329 default :
324- buildFs , err := fs .Sub (portal_ui .GetStaticAssets (), "build" )
325- if err != nil {
326- panic (err )
327- }
328- wrapHandlerSinglePageApplication (requestBounce (http .FileServer (http .FS (buildFs )))).ServeHTTP (w , r )
330+ spaFileHandler .ServeHTTP (w , r )
329331 }
330332 })
331333}
@@ -424,13 +426,10 @@ func handleSPA(w http.ResponseWriter, r *http.Request) {
424426 }
425427 indexPageBytes = replaceLicense (indexPageBytes )
426428
427- mimeType := mimedb .TypeByExtension (filepath .Ext (r .URL .Path ))
428-
429- if mimeType == "application/octet-stream" {
430- mimeType = "text/html"
431- }
432-
433- w .Header ().Set ("Content-Type" , mimeType )
429+ // it's important to force "Content-Type: text/html", because a previous
430+ // handler may have already set the content-type to a different value.
431+ // (i.e. the FileServer when it detected that it couldn't find the file)
432+ w .Header ().Set ("Content-Type" , "text/html" )
434433 http .ServeContent (w , r , "index.html" , time .Now (), bytes .NewReader (indexPageBytes ))
435434}
436435
0 commit comments