From e7c433f1c13b89ced9e0882b641eecc80986c548 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Fri, 10 Oct 2025 20:28:18 +0200 Subject: [PATCH] Add port env option --- .env.example | 5 +++-- .gitignore | 1 + main.go | 10 ++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 2c826ad..20bd063 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,5 @@ DB_PATH=db.sqlite ESI_CLIENT_ID=your-client-id -ESI_REDIRECT_URI=http://localhost:8080/callback -ESI_SCOPES=esi-planets.manage_planets.v1 \ No newline at end of file +ESI_REDIRECT_URI=http://localhost:3000/callback +ESI_SCOPES=esi-planets.manage_planets.v1 +HTTP_SERVER_PORT=3000 \ No newline at end of file diff --git a/.gitignore b/.gitignore index c782abf..ff5f01a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .env *.sqlite +*.exe diff --git a/main.go b/main.go index 7ba3507..86e043f 100644 --- a/main.go +++ b/main.go @@ -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 }