diff options
author | Alan Pearce | 2024-06-13 17:08:33 +0200 |
---|---|---|
committer | Alan Pearce | 2024-06-13 17:08:33 +0200 |
commit | a1ddbf3fa6d1814ebca238d0c4ed54617253689f (patch) | |
tree | 376944e40581b5d8155ab4acf9a0011364041417 | |
parent | 66b66e6118dd43ccbd1e85e33d44a02de7a2b812 (diff) | |
download | website-a1ddbf3fa6d1814ebca238d0c4ed54617253689f.tar.lz website-a1ddbf3fa6d1814ebca238d0c4ed54617253689f.tar.zst website-a1ddbf3fa6d1814ebca238d0c4ed54617253689f.zip |
server: listen on socket provided by system(f)d, if available
-rw-r--r-- | flake.nix | 1 | ||||
-rw-r--r-- | internal/server/server.go | 11 | ||||
-rwxr-xr-x | justfile | 2 |
3 files changed, 12 insertions, 2 deletions
diff --git a/flake.nix b/flake.nix index 2ed262e..ad68d77 100644 --- a/flake.nix +++ b/flake.nix @@ -46,6 +46,7 @@ gomod2nix.packages.${system}.default gci hyperlink + systemfd modd nodePackages.vercel netlify-cli diff --git a/internal/server/server.go b/internal/server/server.go index 4692965..71b9199 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -6,6 +6,7 @@ import ( "net" "net/http" "net/url" + "os" "slices" "time" @@ -145,7 +146,15 @@ func New(runtimeConfig *Config) (*Server, error) { } 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") } diff --git a/justfile b/justfile index 5e8df3d..304eb98 100755 --- a/justfile +++ b/justfile @@ -39,7 +39,7 @@ nix-build what: 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 |