about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2024-04-21 11:21:48 +0200
committerAlan Pearce2024-04-21 11:21:48 +0200
commit24354d97408619fdb77c982edbefd9dbd82d5fff (patch)
tree290157c57049ba5cb4e9772a3584cd6ecfc0d36f
parentec434072a3bacd33e80056a082b6845359f16c2f (diff)
downloadwebsite-24354d97408619fdb77c982edbefd9dbd82d5fff.tar.lz
website-24354d97408619fdb77c982edbefd9dbd82d5fff.tar.zst
website-24354d97408619fdb77c982edbefd9dbd82d5fff.zip
allow listen address to be configured
-rw-r--r--nix/default.nix1
-rw-r--r--server.go4
2 files changed, 4 insertions, 1 deletions
diff --git a/nix/default.nix b/nix/default.nix
index 2032013..d555bbd 100644
--- a/nix/default.nix
+++ b/nix/default.nix
@@ -17,6 +17,7 @@ let
         Cmd = [ "${server}/bin/website" ];
         Env = [
           "PRODUCTION=true"
+          "LISTEN_ADDRESS="
           "PORT=${builtins.toString PORT}"
           "ROOT=public"
         ];
diff --git a/server.go b/server.go
index d7e241e..945ed38 100644
--- a/server.go
+++ b/server.go
@@ -6,6 +6,7 @@ import (
 	"fmt"
 	"io"
 	"log"
+	"net"
 	"net/http"
 	"os"
 	"time"
@@ -31,6 +32,7 @@ import (
 
 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 @@ func main() {
 		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))))
 }