Add port env option
This commit is contained in:
@@ -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
|
||||
ESI_REDIRECT_URI=http://localhost:3000/callback
|
||||
ESI_SCOPES=esi-planets.manage_planets.v1
|
||||
HTTP_SERVER_PORT=3000
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
.env
|
||||
*.sqlite
|
||||
*.exe
|
||||
|
||||
10
main.go
10
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user