job-board icon indicating copy to clipboard operation
job-board copied to clipboard

[DX] make development address configurable

Open ghost opened this issue 3 years ago • 0 comments

when running the server in development mode we currently run it on all interfaces so it can be accessible if you are running the code from another server or from your computer and accessing it from another device.

Listening on all interfaces

| <your go server> | ----  | Internet | ----- | <you trying to access the server> |

allow connection from outside, listen on all interfaces

http.ListenAndServe("0.0.0.0:9876", ...)

Your machine - Loopback interface

| <your go server> - <you trying to access the server |

only allow connection from the inside, listen to the local interface only

http.ListenAndServe("127.0.0.1:9876", ...)

Right now the value is hard-coded to all interfaces

server.go

1038 func (s Server) Run() error {
1039         addr := fmt.Sprintf(":%s", s.cfg.Port)
1040         if s.cfg.Env == "dev" {
1041                 log.Printf("local env http://localhost:%s", s.cfg.Port)
1042                 addr = fmt.Sprintf("0.0.0.0:%s", s.cfg.Port)
1043         }
1044         return http.ListenAndServe(
1045                 addr,
1046                 middleware.HTTPSMiddleware(
1047                         middleware.GzipMiddleware(
1048                                 middleware.LoggingMiddleware(middleware.HeadersMiddleware(s.router, s.cfg.Env)),
1049                         ),
1050                         s.cfg.Env,
1051                 ),
1052         )
1053 }

would be awesome to have the ability to configure this via config. This also removes the annoying popup that appears whenever you run the server locally on all interfaces "allow this machine to accept incoming connections?" etc

ghost avatar Feb 23 '22 01:02 ghost