PORT environment variable always takes priority over database settings. Lock UI, when defined

This commit is contained in:
2025-12-01 14:26:19 +01:00
parent 272e112ac9
commit ac0f634236
9 changed files with 103 additions and 11 deletions

View File

@@ -857,7 +857,25 @@ func GetSettingsHandler(c *gin.Context) {
config.DebugLog("----------------------------")
config.DebugLog("GetSettingsHandler called (handlers.go)") // entry point
s := config.GetSettings()
c.JSON(http.StatusOK, s)
// Check if PORT environment variable is set
envPort, envPortSet := config.GetPortFromEnv()
// Create response with PORT env info
response := make(map[string]interface{})
responseBytes, _ := json.Marshal(s)
json.Unmarshal(responseBytes, &response)
// Add PORT environment variable information
response["portFromEnv"] = envPort
response["portEnvSet"] = envPortSet
// If PORT env is set, override the port value in response
if envPortSet {
response["port"] = envPort
}
c.JSON(http.StatusOK, response)
}
// UpdateSettingsHandler updates the AppSettings from a JSON body
@@ -875,6 +893,13 @@ func UpdateSettingsHandler(c *gin.Context) {
}
config.DebugLog("JSON binding successful, updating settings (handlers.go)")
// Check if PORT environment variable is set - if so, ignore port changes from request
envPort, envPortSet := config.GetPortFromEnv()
if envPortSet {
// Don't allow port changes when PORT env is set
req.Port = envPort
}
oldSettings := config.GetSettings()
newSettings, err := config.UpdateSettings(req)
if err != nil {