about summary refs log tree commit diff stats
path: root/cmd/server
diff options
context:
space:
mode:
authorAlan Pearce2024-06-11 10:07:25 +0200
committerAlan Pearce2024-06-11 10:07:25 +0200
commit66b66e6118dd43ccbd1e85e33d44a02de7a2b812 (patch)
tree32987723187ddac9d3a8aa8187aa20080aa5c91d /cmd/server
parente89fbd7ef3e418629ea2533cf4fa9707fe51950f (diff)
downloadwebsite-66b66e6118dd43ccbd1e85e33d44a02de7a2b812.tar.lz
website-66b66e6118dd43ccbd1e85e33d44a02de7a2b812.tar.zst
website-66b66e6118dd43ccbd1e85e33d44a02de7a2b812.zip
server: automatically build, re-build and reload in dev
Diffstat (limited to 'cmd/server')
-rw-r--r--cmd/server/main.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/cmd/server/main.go b/cmd/server/main.go
index 464c438..51a9e52 100644
--- a/cmd/server/main.go
+++ b/cmd/server/main.go
@@ -28,7 +28,16 @@ func main() {
 		}
 		panic("parsing runtime configuration" + err.Error())
 	}
-	log.Configure(runtimeConfig.Production)
+	log.Configure(!runtimeConfig.Development)
+
+	if runtimeConfig.Development {
+		tmpdir, err := os.MkdirTemp("", "website")
+		if err != nil {
+			log.Fatal("could not create temporary directory to build website: %v", err)
+		}
+		runtimeConfig.Root = tmpdir
+		defer os.RemoveAll(tmpdir)
+	}
 
 	c := make(chan os.Signal, 2)
 	signal.Notify(c, os.Interrupt)
@@ -52,9 +61,7 @@ func main() {
 		defer wg.Done()
 		sErr <- sv.Start()
 	}()
-	if !runtimeConfig.InDevServer {
-		log.Info("server listening", "address", sv.Addr)
-	}
+	log.Info("server listening", "address", sv.Addr)
 
 	err = <-sErr
 	if err != nil {