From dfe19c4c3af78474c1047b36a9efa68d97294f67 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Tue, 15 Mar 2022 09:18:35 +0100 Subject: [PATCH] Fix exported auth assets serving in non-dev mode --- auth/auth.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index e0aceb88c..7af8e4d00 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -396,23 +396,29 @@ func (svc service) MountHttpRoutes(basePath string, r chi.Router) { svc.handlers.MountHttpRoutes(r) const uriRoot = "/auth/assets/public" - if svc.opt.DevelopmentMode { + var ( + assetHandler http.Handler + useEmbedded = len(svc.opt.AssetsPath) == 0 + ) + + if useEmbedded { + assetHandler = http.StripPrefix(basePath+"/auth/", http.FileServer(http.FS(PublicAssets))) + } else { var root = strings.TrimRight(svc.opt.AssetsPath, "/") + "/public" if err := dirCheck(root); err != nil { svc.log.Error( - "failed to run in development mode (AUTH_DEVELOPMENT_MODE=true)", + "failed to configure auth assets handler", zap.Error(err), zap.String("AUTH_ASSETS_PATH", svc.opt.AssetsPath), ) } else { - r.Handle(uriRoot+"/*", http.StripPrefix(basePath+uriRoot, http.FileServer(http.Dir(root)))) - return + assetHandler = http.StripPrefix(basePath+uriRoot, http.FileServer(http.Dir(root))) } } // fallback to embedded assets - r.Handle(uriRoot+"/*", http.StripPrefix(basePath+"/auth/", http.FileServer(http.FS(PublicAssets)))) + r.Handle(uriRoot+"/*", assetHandler) } // checks if directory exists & is readable