about summary refs log tree commit diff stats
path: root/internal
diff options
context:
space:
mode:
authorAlan Pearce2024-06-25 20:11:20 +0200
committerAlan Pearce2024-06-25 20:11:20 +0200
commit2fcf88ac2e088cdb7692ccfd7fccce01dd0cd523 (patch)
tree1a10913622f35818cade49d1856f0d999ff65fbd /internal
parent1b734d8731f4d5ada6ca0da07e2bcf59e00f209d (diff)
downloadwebsite-2fcf88ac2e088cdb7692ccfd7fccce01dd0cd523.tar.lz
website-2fcf88ac2e088cdb7692ccfd7fccce01dd0cd523.tar.zst
website-2fcf88ac2e088cdb7692ccfd7fccce01dd0cd523.zip
refactor server startup
Diffstat (limited to 'internal')
-rw-r--r--internal/builder/builder.go11
-rw-r--r--internal/server/server.go31
2 files changed, 16 insertions, 26 deletions
diff --git a/internal/builder/builder.go b/internal/builder/builder.go
index d2d86a6..1181802 100644
--- a/internal/builder/builder.go
+++ b/internal/builder/builder.go
@@ -4,7 +4,6 @@ import (
 	"context"
 	"fmt"
 	"io"
-	"net/url"
 	"os"
 	"path"
 	"slices"
@@ -24,8 +23,7 @@ import (
 type IOConfig struct {
 	Source      string `conf:"default:.,short:s,flag:src"`
 	Destination string `conf:"default:website,short:d,flag:dest"`
-	BaseURL     config.URL
-	Development bool `conf:"default:false,flag:dev"`
+	Development bool   `conf:"default:false,flag:dev"`
 }
 
 type Result struct {
@@ -267,13 +265,6 @@ func BuildSite(ioConfig IOConfig) (*Result, error) {
 	config.InjectLiveReload = ioConfig.Development
 	compressFiles = !ioConfig.Development
 
-	if ioConfig.BaseURL.URL != nil {
-		config.BaseURL.URL, err = url.Parse(ioConfig.BaseURL.String())
-		if err != nil {
-			return nil, errors.WithMessage(err, "could not re-parse base URL")
-		}
-	}
-
 	if ioConfig.Development && ioConfig.Destination != "website" {
 		err = os.RemoveAll(ioConfig.Destination)
 		if err != nil {
diff --git a/internal/server/server.go b/internal/server/server.go
index 556c660..02202ae 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -103,6 +103,13 @@ func New(runtimeConfig *Config) (*Server, error) {
 			return nil, err
 		}
 		runtimeConfig.Root = "website"
+	} else {
+		tmpdir, err := os.MkdirTemp("", "website")
+		if err != nil {
+			return nil, err
+		}
+		defer os.RemoveAll(tmpdir)
+		runtimeConfig.Root = tmpdir
 	}
 
 	config, err := cfg.GetConfig()
@@ -113,15 +120,14 @@ func New(runtimeConfig *Config) (*Server, error) {
 	listenAddress := net.JoinHostPort(runtimeConfig.ListenAddress, strconv.Itoa(runtimeConfig.Port))
 	top := http.NewServeMux()
 
+	builderConfig := builder.IOConfig{
+		Source:      "content",
+		Destination: runtimeConfig.Root,
+		Development: runtimeConfig.Development,
+	}
+
 	if runtimeConfig.Development {
 		applyDevModeOverrides(config, listenAddress)
-		builderConfig := builder.IOConfig{
-			Source:      "content",
-			Destination: runtimeConfig.Root,
-			BaseURL:     config.BaseURL,
-			Development: true,
-		}
-		rebuild(builderConfig, config)
 
 		liveReload := livereload.New()
 		top.Handle("/_/reload", liveReload)
@@ -147,22 +153,15 @@ func New(runtimeConfig *Config) (*Server, error) {
 		go fw.Start(func(filename string) {
 			rebuild(builderConfig, config)
 		})
-	} else {
-		builderConfig := builder.IOConfig{
-			Source:      "content",
-			Destination: runtimeConfig.Root,
-			BaseURL:     config.BaseURL,
-			Development: false,
-		}
-		rebuild(builderConfig, config)
 	}
 
+	rebuild(builderConfig, config)
+
 	loggingMux := http.NewServeMux()
 	mux, err := website.NewMux(config, runtimeConfig.Root)
 	if err != nil {
 		return nil, errors.Wrap(err, "could not create website mux")
 	}
-	log.Debug("binding main handler to", "host", listenAddress)
 
 	if runtimeConfig.Development || runtimeConfig.Redirect {
 		loggingMux.Handle(config.BaseURL.Hostname()+"/", mux)