feat(admin): add -urlPrefix flag for subdirectory deployment (#8670)
Allow the admin server to run behind a reverse proxy under a subdirectory by adding a -urlPrefix flag (e.g. -urlPrefix=/seaweedfs). Closes #8646
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
package layout
|
||||
|
||||
import "net/http"
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/seaweedfs/seaweedfs/weed/admin/dash"
|
||||
)
|
||||
|
||||
// ViewContext contains per-request metadata needed by layout templates.
|
||||
type ViewContext struct {
|
||||
Request *http.Request
|
||||
Username string
|
||||
CSRFToken string
|
||||
URLPrefix string
|
||||
}
|
||||
|
||||
// NewViewContext builds a ViewContext from request metadata.
|
||||
@@ -15,5 +21,11 @@ func NewViewContext(r *http.Request, username, csrfToken string) ViewContext {
|
||||
Request: r,
|
||||
Username: username,
|
||||
CSRFToken: csrfToken,
|
||||
URLPrefix: dash.URLPrefixFromContext(r.Context()),
|
||||
}
|
||||
}
|
||||
|
||||
// P returns the URL prefix prepended to the given path as a templ.SafeURL.
|
||||
func (v ViewContext) P(path string) templ.SafeURL {
|
||||
return templ.SafeURL(v.URLPrefix + path)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user