@@ -313,6 +313,12 @@ func AuthenticationMiddleware(next http.Handler) http.Handler {
313
313
314
314
// FileServerMiddleware serves files from the static folder
315
315
func 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
+
316
322
return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
317
323
w .Header ().Set ("Server" , globalAppName ) // do not add version information
318
324
switch {
@@ -321,11 +327,7 @@ func FileServerMiddleware(next http.Handler) http.Handler {
321
327
case strings .HasPrefix (r .URL .Path , "/api" ):
322
328
next .ServeHTTP (w , r )
323
329
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 )
329
331
}
330
332
})
331
333
}
@@ -424,13 +426,10 @@ func handleSPA(w http.ResponseWriter, r *http.Request) {
424
426
}
425
427
indexPageBytes = replaceLicense (indexPageBytes )
426
428
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" )
434
433
http .ServeContent (w , r , "index.html" , time .Now (), bytes .NewReader (indexPageBytes ))
435
434
}
436
435
0 commit comments