fix: adapt for subpath reverse proxies, embed web assets and fix relative URLs
This commit is contained in:
@@ -2,27 +2,53 @@ package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Port string
|
||||
BasePath string
|
||||
AppOrigin string
|
||||
SessionSecret string
|
||||
TurnstileSecret string
|
||||
Port string
|
||||
BasePath string
|
||||
AppOrigin string
|
||||
SessionSecret string
|
||||
TurnstileSecret string
|
||||
TurnstileSiteKey string
|
||||
DBPath string
|
||||
DBPath string
|
||||
AppDir string
|
||||
}
|
||||
|
||||
func Load() *Config {
|
||||
appDir := os.Getenv("APP_DIR")
|
||||
if appDir == "" {
|
||||
appDir = "."
|
||||
}
|
||||
|
||||
// BasePath: no Mini PaaS, as requisições chegam com prefixo já removido, portanto "" é o ideal.
|
||||
// Se o usuário passar BASE_PATH explicitamente, respeita a variável.
|
||||
basePath := os.Getenv("BASE_PATH")
|
||||
|
||||
dbPath := os.Getenv("DB_PATH")
|
||||
if dbPath == "" {
|
||||
dbPath = filepath.Join(appDir, "data", "initpage.db")
|
||||
}
|
||||
|
||||
appOrigin := os.Getenv("APP_ORIGIN")
|
||||
if appOrigin == "" {
|
||||
domain := os.Getenv("PAAS_DOMAIN")
|
||||
if domain == "" {
|
||||
domain = "paas.weltonmoura.com.br"
|
||||
}
|
||||
appOrigin = "https://" + domain
|
||||
}
|
||||
|
||||
return &Config{
|
||||
Port: getEnv("PORT", "8080"),
|
||||
BasePath: getEnv("BASE_PATH", "/initpage"),
|
||||
AppOrigin: getEnv("APP_ORIGIN", "https://apps.weltonmoura.com.br"),
|
||||
SessionSecret: getEnv("SESSION_SECRET", "dev-secret-change-me"),
|
||||
TurnstileSecret: getEnv("TURNSTILE_SECRET", ""),
|
||||
Port: getEnv("PORT", "8080"),
|
||||
BasePath: basePath,
|
||||
AppOrigin: appOrigin,
|
||||
SessionSecret: getEnv("SESSION_SECRET", "dev-secret-change-me"),
|
||||
TurnstileSecret: getEnv("TURNSTILE_SECRET", ""),
|
||||
TurnstileSiteKey: getEnv("TURNSTILE_SITEKEY", ""),
|
||||
DBPath: getEnv("DB_PATH", "./data/initpage.db"),
|
||||
DBPath: dbPath,
|
||||
AppDir: appDir,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user