api: add COMMENTO_BIND_ADDRESS variable
Signed-off-by: Pierre-Alain TORET <pierre-alain.toret@protonmail.com>
This commit is contained in:
parent
684734cb29
commit
73d04bf857
@ -16,6 +16,7 @@ func parseConfig() error {
|
||||
defaults := map[string]string{
|
||||
"POSTGRES": "postgres://postgres:postgres@localhost/commento?sslmode=disable",
|
||||
|
||||
"BIND_ADDRESS": "127.0.0.1",
|
||||
"PORT": "8080",
|
||||
"ORIGIN": "",
|
||||
|
||||
|
@ -14,6 +14,23 @@ func TestParseConfigBasics(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
if os.Getenv("BIND_ADDRESS") != "127.0.0.1" {
|
||||
t.Errorf("expected BIND_ADDRESS=127.0.0.1, but BIND_ADDRESS=%s instead", os.Getenv("BIND_ADDRESS"))
|
||||
return
|
||||
}
|
||||
|
||||
os.Setenv("COMMENTO_BIND_ADDRESS", "192.168.1.100")
|
||||
|
||||
if err := parseConfig(); err != nil {
|
||||
t.Errorf("unexpected error when parsing config: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if os.Getenv("BIND_ADDRESS") != "192.168.1.100" {
|
||||
t.Errorf("expected BIND_ADDRESS=192.168.1.100, but BIND_ADDRESS=%s instead", os.Getenv("BIND_ADDRESS"))
|
||||
return
|
||||
}
|
||||
|
||||
// This test feels kinda stupid, but whatever.
|
||||
if os.Getenv("PORT") != "8080" {
|
||||
t.Errorf("expected PORT=8080, but PORT=%s instead", os.Getenv("PORT"))
|
||||
|
@ -22,8 +22,10 @@ func serveRoutes() error {
|
||||
headers := handlers.AllowedHeaders([]string{"X-Requested-With"})
|
||||
methods := handlers.AllowedMethods([]string{"GET", "POST"})
|
||||
|
||||
logger.Infof("starting server on port %s\n", os.Getenv("PORT"))
|
||||
if err := http.ListenAndServe(":"+os.Getenv("PORT"), handlers.CORS(origins, headers, methods)(router)); err != nil {
|
||||
addrPort := os.Getenv("BIND_ADDRESS") + ":" + os.Getenv("PORT")
|
||||
|
||||
logger.Infof("starting server on %s\n", addrPort)
|
||||
if err := http.ListenAndServe(addrPort, handlers.CORS(origins, headers, methods)(router)); err != nil {
|
||||
logger.Errorf("cannot start server: %v", err)
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user