all repos — website @ a1ddbf3fa6d1814ebca238d0c4ed54617253689f

My website

server: listen on socket provided by system(f)d, if available
Alan Pearce alan@alanpearce.eu
Thu, 13 Jun 2024 17:08:33 +0200
commit

a1ddbf3fa6d1814ebca238d0c4ed54617253689f

parent

66b66e6118dd43ccbd1e85e33d44a02de7a2b812

3 files changed, 12 insertions(+), 2 deletions(-)

jump to
M flake.nixflake.nix
@@ -46,6 +46,7 @@ go-tools                 gomod2nix.packages.${system}.default
                 gci
                 hyperlink
+                systemfd
                 modd
                 nodePackages.vercel
                 netlify-cli
M internal/server/server.gointernal/server/server.go
@@ -6,6 +6,7 @@ "fmt" 	"net"
 	"net/http"
 	"net/url"
+	"os"
 	"slices"
 	"time"
 
@@ -145,7 +146,15 @@ }, nil }
 
 func (s *Server) Start() error {
-	if err := s.ListenAndServe(); err != http.ErrServerClosed {
+	f := os.NewFile(uintptr(3), "")
+	l, err := net.FileListener(f)
+	if err != nil {
+		l, err = net.Listen("tcp", s.Addr)
+		if err != nil {
+			return errors.Wrap(err, "could not create listener")
+		}
+	}
+	if err := http.Serve(l, s.Handler); err != http.ErrServerClosed {
 		return errors.Wrap(err, "error creating/closing server")
 	}
 
M justfilejustfile
@@ -39,7 +39,7 @@ watch-server: (watch-flake "watchexec -r -i content -i templates go run ./cmd/server")
 
 dev:
-	modd
+	systemfd -s http::3000 modd
 
 docker-stream system=(arch() + "-linux"):
     @nix build --print-out-paths .#docker-stream-{{ system }} | sh