Skip to content

Commit 4f53756

Browse files
committed
allow port to be configured
1 parent 0d61b12 commit 4f53756

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

framework/h/app.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ type AppOpts struct {
135135
LiveReload bool
136136
ServiceLocator *service.Locator
137137
Register func(app *App)
138+
Port int
138139
}
139140

140141
type App struct {
@@ -229,6 +230,15 @@ func (app *App) start() {
229230
}
230231

231232
port := ":3000"
233+
234+
if os.Getenv("PORT") != "" {
235+
port = fmt.Sprintf(":%s", os.Getenv("PORT"))
236+
}
237+
238+
if app.Opts.Port != 0 {
239+
port = fmt.Sprintf(":%d", app.Opts.Port)
240+
}
241+
232242
slog.Info(fmt.Sprintf("Server started at localhost%s", port))
233243

234244
if err := http.ListenAndServe(port, app.Router); err != nil {

htmgo-site/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func main() {
2323

2424
h.Start(h.AppOpts{
2525
ServiceLocator: locator,
26+
Port: 3002,
2627
LiveReload: true,
2728
Register: func(app *h.App) {
2829

0 commit comments

Comments
 (0)