File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed
Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Original file line number Diff line number Diff 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
140141type 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 {
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments