fix(config): make FRONTEND_URL optional and default to APP_URL
This commit is contained in:
parent
bfae47f584
commit
5fb92fd582
4 changed files with 21 additions and 8 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/hex"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
|
@ -29,14 +30,19 @@ func Load() Config {
|
|||
cfg := Config{
|
||||
Port: env("PORT", "8080"),
|
||||
DBPath: env("DB_PATH", "wannpassts.db"),
|
||||
AppURL: env("APP_URL", "http://localhost:8080"),
|
||||
FrontendURL: env("FRONTEND_URL", "http://localhost:5173"),
|
||||
AppURL: strings.TrimSuffix(env("APP_URL", "http://localhost:8080"), "/"),
|
||||
FrontendURL: strings.TrimSuffix(os.Getenv("FRONTEND_URL"), "/"),
|
||||
JWTSecret: os.Getenv("JWT_SECRET"),
|
||||
EncryptionKey: os.Getenv("ENCRYPTION_KEY"),
|
||||
GoogleClientID: os.Getenv("GOOGLE_CLIENT_ID"),
|
||||
GoogleClientSecret: os.Getenv("GOOGLE_CLIENT_SECRET"),
|
||||
StaticDir: env("STATIC_DIR", ""),
|
||||
}
|
||||
// FRONTEND_URL ist optional: Ohne eigenen Wert leiten Google-Callbacks etc.
|
||||
// auf die öffentliche App-URL (APP_URL) – wichtig für Single-Origin-Deployments.
|
||||
if cfg.FrontendURL == "" {
|
||||
cfg.FrontendURL = cfg.AppURL
|
||||
}
|
||||
if cfg.JWTSecret == "" {
|
||||
cfg.JWTSecret = randomHex(32)
|
||||
log.Println("WARNUNG: JWT_SECRET nicht gesetzt – temporäres Secret erzeugt (Sessions verfallen bei Neustart).")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue