Add port env option

This commit is contained in:
2025-10-10 20:28:18 +02:00
parent a1f568cbe6
commit e7c433f1c1
3 changed files with 12 additions and 4 deletions

10
main.go
View File

@@ -20,6 +20,7 @@ type Options struct {
RedirectURI string
Scopes []string
DBPath string
Port string
}
var options Options
@@ -82,9 +83,9 @@ func main() {
ctx.WriteString("Authenticated! Access token: " + token)
})
logger.Info("Starting web server on :3000")
logger.Info("Starting web server on 0.0.0.0:%s", options.Port)
go func() {
if err := fasthttp.ListenAndServe(":3000", r.Handler); err != nil {
if err := fasthttp.ListenAndServe("0.0.0.0:"+options.Port, r.Handler); err != nil {
logger.Error("Server failed: %v", err)
}
}()
@@ -120,11 +121,16 @@ func LoadOptions() (Options, error) {
if dbPath == "" {
return Options{}, fmt.Errorf("DB_PATH is required in .env file")
}
port := os.Getenv("HTTP_SERVER_PORT")
if port == "" {
return Options{}, fmt.Errorf("HTTP_SERVER_PORT is required in .env file")
}
return Options{
ClientID: clientID,
RedirectURI: redirectURI,
Scopes: scopes,
DBPath: dbPath,
Port: port,
}, nil
}