Skip to content

Commit

Permalink
Add LISTEN_ADDRESS env variables and set to 127.0.0.1 by default (dev…
Browse files Browse the repository at this point in the history
… environments)

By only listening on the loopback address, we avoid the prompt about incoming networking connections from MacOS and other OSs.
See nodejs/node#37233
  • Loading branch information
johnwarden committed Dec 9, 2022
1 parent 69cb375 commit 270a298
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export SQLITE_DATA_DIR=data
export CACHE_SIZE=100

export LISTEN_ADDRESS=127.0.0.1

echo "Successfully loaded .envrc"

Expand Down
4 changes: 3 additions & 1 deletion httpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ func (app app) httpServer(onPanic func(error)) *http.Server {
port = "8080"
}

listenAddress := os.Getenv("LISTEN_ADDRESS")

staticRoot, err := fs.Sub(staticFS, "static")
if err != nil {
LogFatal(l, "fs.Sub", err)
}

server := &http.Server{
Addr: ":" + port,
Addr: listenAddress + ":" + port,
WriteTimeout: writeTimeout,
ReadHeaderTimeout: readHeaderTimeout,
}
Expand Down
5 changes: 4 additions & 1 deletion prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"net/http"
"os"
"time"

"github.com/VictoriaMetrics/metrics"
Expand Down Expand Up @@ -31,8 +32,10 @@ func servePrometheusMetrics() func(ctx context.Context) error {
metrics.WritePrometheus(w, true)
})

listenAddress := os.Getenv("LISTEN_ADDRESS")

s := &http.Server{
Addr: ":9091",
Addr: listenAddress + ":9091",
Handler: mux,
}

Expand Down

0 comments on commit 270a298

Please sign in to comment.