about summary refs log tree commit diff stats
path: root/internal/server
diff options
context:
space:
mode:
authorAlan Pearce2024-05-12 12:56:47 +0200
committerAlan Pearce2024-05-12 12:56:47 +0200
commit68cd867bf76a0bfe6c07c13acb25ac231de4998f (patch)
tree33ab31d54a5c5b824910ef6f07e365394ce2c183 /internal/server
parent628c2a858191cde34478b760b3c8c6c23a420088 (diff)
downloadsearchix-68cd867bf76a0bfe6c07c13acb25ac231de4998f.tar.lz
searchix-68cd867bf76a0bfe6c07c13acb25ac231de4998f.tar.zst
searchix-68cd867bf76a0bfe6c07c13acb25ac231de4998f.zip
build: optimise and fix handing of csp headers in dev mode
Diffstat (limited to 'internal/server')
-rw-r--r--internal/server/mux.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/internal/server/mux.go b/internal/server/mux.go
index ee7daed..95b7e14 100644
--- a/internal/server/mux.go
+++ b/internal/server/mux.go
@@ -11,7 +11,6 @@ import (
 	"net/url"
 	"os"
 	"path"
-	"slices"
 	"strconv"
 	"time"
 
@@ -69,8 +68,10 @@ type ResultData[T options.NixOption] struct {
 }
 
 func applyDevModeOverrides(config *cfg.Config) {
-	config.CSP.ScriptSrc = slices.Insert(config.CSP.ScriptSrc, 0, "'unsafe-inline'")
-	config.CSP.ConnectSrc = slices.Insert(config.CSP.ConnectSrc, 0, "'self'")
+	if len(config.CSP.ScriptSrc) == 0 {
+		config.CSP.ScriptSrc = config.CSP.DefaultSrc
+	}
+	config.CSP.ScriptSrc = append(config.CSP.ScriptSrc, "'unsafe-inline'")
 }
 
 func NewMux(runtimeConfig *Config) (*http.ServeMux, error) {