allow port to be configured
This commit is contained in:
parent
0d61b12561
commit
4f537567ad
2 changed files with 11 additions and 0 deletions
|
|
@ -135,6 +135,7 @@ type AppOpts struct {
|
|||
LiveReload bool
|
||||
ServiceLocator *service.Locator
|
||||
Register func(app *App)
|
||||
Port int
|
||||
}
|
||||
|
||||
type App struct {
|
||||
|
|
@ -229,6 +230,15 @@ func (app *App) start() {
|
|||
}
|
||||
|
||||
port := ":3000"
|
||||
|
||||
if os.Getenv("PORT") != "" {
|
||||
port = fmt.Sprintf(":%s", os.Getenv("PORT"))
|
||||
}
|
||||
|
||||
if app.Opts.Port != 0 {
|
||||
port = fmt.Sprintf(":%d", app.Opts.Port)
|
||||
}
|
||||
|
||||
slog.Info(fmt.Sprintf("Server started at localhost%s", port))
|
||||
|
||||
if err := http.ListenAndServe(port, app.Router); err != nil {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ func main() {
|
|||
|
||||
h.Start(h.AppOpts{
|
||||
ServiceLocator: locator,
|
||||
Port: 3002,
|
||||
LiveReload: true,
|
||||
Register: func(app *h.App) {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue