all repos — website @ 24354d97408619fdb77c982edbefd9dbd82d5fff

My website

allow listen address to be configured
Alan Pearce alan@alanpearce.eu
Sun, 21 Apr 2024 11:21:48 +0200
commit

24354d97408619fdb77c982edbefd9dbd82d5fff

parent

ec434072a3bacd33e80056a082b6845359f16c2f

2 files changed, 4 insertions(+), 1 deletions(-)

jump to
M nix/default.nixnix/default.nix
@@ -17,6 +17,7 @@ config = {         Cmd = [ "${server}/bin/website" ];
         Env = [
           "PRODUCTION=true"
+          "LISTEN_ADDRESS="
           "PORT=${builtins.toString PORT}"
           "ROOT=public"
         ];
M server.goserver.go
@@ -6,6 +6,7 @@ "errors" 	"fmt"
 	"io"
 	"log"
+	"net"
 	"net/http"
 	"os"
 	"time"
@@ -31,6 +32,7 @@ ) 
 type Config struct {
 	Production             bool    `conf:"default:false"`
+	ListenAddress          string  `conf:"default:localhost"`
 	Port                   uint16  `conf:"default:3000,short:p"`
 	BaseURL                cfg.URL `conf:"default:http://localhost:3000,short:b"`
 	RedirectOtherHostnames bool    `conf:"default:false"`
@@ -185,5 +187,5 @@ go func() { 		err := metricServer.Listen(":9091")
 		log.Printf("failed to start metrics server: %v", err)
 	}()
-	log.Fatal(toplevel.Listen(fmt.Sprintf("%s:%d", "", runtimeConfig.Port)))
+	log.Fatal(toplevel.Listen(net.JoinHostPort(runtimeConfig.ListenAddress, fmt.Sprint(runtimeConfig.Port))))
 }