diff --git a/framework/h/app.go b/framework/h/app.go index f45b43b..bdeb585 100644 --- a/framework/h/app.go +++ b/framework/h/app.go @@ -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 { diff --git a/htmgo-site/main.go b/htmgo-site/main.go index 35914f3..019a1a1 100644 --- a/htmgo-site/main.go +++ b/htmgo-site/main.go @@ -23,6 +23,7 @@ func main() { h.Start(h.AppOpts{ ServiceLocator: locator, + Port: 3002, LiveReload: true, Register: func(app *h.App) {