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

View File

@@ -1,4 +1,5 @@
DB_PATH=db.sqlite DB_PATH=db.sqlite
ESI_CLIENT_ID=your-client-id ESI_CLIENT_ID=your-client-id
ESI_REDIRECT_URI=http://localhost:8080/callback ESI_REDIRECT_URI=http://localhost:3000/callback
ESI_SCOPES=esi-planets.manage_planets.v1 ESI_SCOPES=esi-planets.manage_planets.v1
HTTP_SERVER_PORT=3000

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
.env .env
*.sqlite *.sqlite
*.exe

10
main.go
View File

@@ -20,6 +20,7 @@ type Options struct {
RedirectURI string RedirectURI string
Scopes []string Scopes []string
DBPath string DBPath string
Port string
} }
var options Options var options Options
@@ -82,9 +83,9 @@ func main() {
ctx.WriteString("Authenticated! Access token: " + token) 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() { 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) logger.Error("Server failed: %v", err)
} }
}() }()
@@ -120,11 +121,16 @@ func LoadOptions() (Options, error) {
if dbPath == "" { if dbPath == "" {
return Options{}, fmt.Errorf("DB_PATH is required in .env file") 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{ return Options{
ClientID: clientID, ClientID: clientID,
RedirectURI: redirectURI, RedirectURI: redirectURI,
Scopes: scopes, Scopes: scopes,
DBPath: dbPath, DBPath: dbPath,
Port: port,
}, nil }, nil
} }