@@ -318,17 +318,18 @@ func AuthenticationMiddleware(next http.Handler) http.Handler {
318318func FileServerMiddleware (next http.Handler ) http.Handler {
319319 return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
320320 w .Header ().Set ("Server" , globalAppName ) // do not add version information
321+ basePath := GetSubPath ()
321322 switch {
322- case strings .HasPrefix (r .URL .Path , "/ ws" ):
323+ case strings .HasPrefix (r .URL .Path , basePath + " ws" ):
323324 serveWS (w , r )
324- case strings .HasPrefix (r .URL .Path , "/ api" ):
325+ case strings .HasPrefix (r .URL .Path , basePath + " api" ):
325326 next .ServeHTTP (w , r )
326327 default :
327328 buildFs , err := fs .Sub (portal_ui .GetStaticAssets (), "build" )
328329 if err != nil {
329330 panic (err )
330331 }
331- wrapHandlerSinglePageApplication (requestBounce (http .FileServer (http .FS (buildFs )))).ServeHTTP (w , r )
332+ wrapHandlerSinglePageApplication (requestBounce (http .StripPrefix ( basePath , http . FileServer (http .FS (buildFs ) )))).ServeHTTP (w , r )
332333 }
333334 })
334335}
@@ -354,7 +355,7 @@ func (w *notFoundRedirectRespWr) Write(p []byte) (int, error) {
354355
355356// handleSPA handles the serving of the React Single Page Application
356357func handleSPA (w http.ResponseWriter , r * http.Request ) {
357- basePath := "/"
358+ basePath := GetSubPath ()
358359 // For SPA mode we will replace root base with a sub path if configured unless we received cp=y and cpb=/NEW/BASE
359360 if v := r .URL .Query ().Get ("cp" ); v == "y" {
360361 if base := r .URL .Query ().Get ("cpb" ); base != "" {
@@ -419,11 +420,11 @@ func handleSPA(w http.ResponseWriter, r *http.Request) {
419420 }
420421
421422 // if we have a seeded basePath. This should override CONSOLE_SUBPATH every time, thus the `if else`
422- if basePath != "/" {
423+ if basePath != GetSubPath () {
423424 indexPageBytes = replaceBaseInIndex (indexPageBytes , basePath )
424425 // if we have a custom subpath replace it in
425- } else if getSubPath () != "/" {
426- indexPageBytes = replaceBaseInIndex (indexPageBytes , getSubPath ())
426+ } else if GetSubPath () != "/" {
427+ indexPageBytes = replaceBaseInIndex (indexPageBytes , GetSubPath ())
427428 }
428429 indexPageBytes = replaceLicense (indexPageBytes )
429430
@@ -440,7 +441,7 @@ func handleSPA(w http.ResponseWriter, r *http.Request) {
440441// wrapHandlerSinglePageApplication handles a http.FileServer returning a 404 and overrides it with index.html
441442func wrapHandlerSinglePageApplication (h http.Handler ) http.HandlerFunc {
442443 return func (w http.ResponseWriter , r * http.Request ) {
443- if r . URL . Path == "/" {
444+ if match , _ := regexp . MatchString ( fmt . Sprintf ( "^%s/?$" , GetSubPath ()), r . URL . Path ); match {
444445 handleSPA (w , r )
445446 return
446447 }
@@ -469,7 +470,7 @@ func configureServer(s *http.Server, _, _ string) {
469470 s .ErrorLog = log .New (& nullWriter {}, "" , 0 )
470471}
471472
472- func getSubPath () string {
473+ func GetSubPath () string {
473474 subPathOnce .Do (func () {
474475 subPath = parseSubPath (env .Get (SubPath , "" ))
475476 })
0 commit comments