mirror of
https://github.com/h44z/wg-portal.git
synced 2025-12-17 03:46:18 +00:00
allow setting a base-path for the web UI and API (#583)
This commit is contained in:
@@ -149,6 +149,7 @@ func defaultConfig() *Config {
|
||||
RequestLogging: getEnvBool("WG_PORTAL_WEB_REQUEST_LOGGING", false),
|
||||
ExposeHostInfo: getEnvBool("WG_PORTAL_WEB_EXPOSE_HOST_INFO", false),
|
||||
ExternalUrl: getEnvStr("WG_PORTAL_WEB_EXTERNAL_URL", "http://localhost:8888"),
|
||||
BasePath: getEnvStr("WG_PORTAL_WEB_BASE_PATH", ""),
|
||||
ListeningAddress: getEnvStr("WG_PORTAL_WEB_LISTENING_ADDRESS", ":8888"),
|
||||
SessionIdentifier: getEnvStr("WG_PORTAL_WEB_SESSION_IDENTIFIER", "wgPortalSession"),
|
||||
SessionSecret: getEnvStr("WG_PORTAL_WEB_SESSION_SECRET", "very_secret"),
|
||||
|
||||
@@ -11,6 +11,10 @@ type WebConfig struct {
|
||||
// ExternalUrl is the URL where a client can access WireGuard Portal.
|
||||
// This is used for the callback URL of the OAuth providers.
|
||||
ExternalUrl string `yaml:"external_url"`
|
||||
// BasePath is an optional URL path prefix under which the whole web UI and API are served.
|
||||
// Example: "/wg" will make the UI available at /wg/app and the API at /wg/api.
|
||||
// Empty string means no prefix (served from root path).
|
||||
BasePath string `yaml:"base_path"`
|
||||
// ListeningAddress is the address and port for the web server.
|
||||
ListeningAddress string `yaml:"listening_address"`
|
||||
// SessionIdentifier is the session identifier for the web frontend.
|
||||
@@ -35,4 +39,12 @@ type WebConfig struct {
|
||||
|
||||
func (c *WebConfig) Sanitize() {
|
||||
c.ExternalUrl = strings.TrimRight(c.ExternalUrl, "/")
|
||||
|
||||
// normalize BasePath: allow empty, otherwise ensure leading slash, no trailing slash
|
||||
p := strings.TrimSpace(c.BasePath)
|
||||
p = strings.TrimRight(p, "/")
|
||||
if p != "" && !strings.HasPrefix(p, "/") {
|
||||
p = "/" + p
|
||||
}
|
||||
c.BasePath = p
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user