diff options
author | Alan Pearce | 2024-06-26 23:10:51 +0200 |
---|---|---|
committer | Alan Pearce | 2024-06-26 23:10:51 +0200 |
commit | d5b95136d5f162645a6bfaa76833cbf5520f7e45 (patch) | |
tree | 41ceb9a1011418a77d6f9472e0fafe84c3eb27ff /internal/server/server.go | |
parent | 98e63f34bd0ffa9087f7e2640d60d6d1c30ecc13 (diff) | |
download | website-d5b95136d5f162645a6bfaa76833cbf5520f7e45.tar.lz website-d5b95136d5f162645a6bfaa76833cbf5520f7e45.tar.zst website-d5b95136d5f162645a6bfaa76833cbf5520f7e45.zip |
enable TLS for local development (using caddy as acme server)
Diffstat (limited to 'internal/server/server.go')
-rw-r--r-- | internal/server/server.go | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/internal/server/server.go b/internal/server/server.go index 3110ec0..717320d 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -9,6 +9,7 @@ import ( "os" "slices" "strconv" + "strings" "time" "website/internal/builder" @@ -31,13 +32,16 @@ var ( ) type Config struct { - Development bool `conf:"default:false,flag:dev"` Root string `conf:"default:website"` Redirect bool `conf:"default:true"` ListenAddress string `conf:"default:localhost"` - Port int `conf:"default:3000,short:p"` - TLSPort int `conf:"default:443"` + Port int `conf:"default:8080,short:p"` + TLSPort int `conf:"default:8443"` TLS bool `conf:"default:false"` + + Development bool `conf:"default:false,flag:dev"` + ACMECACert string `conf:"env:ACME_CA_CERT"` + Domains string } type Server struct { @@ -46,13 +50,18 @@ type Server struct { config *cfg.Config } -func applyDevModeOverrides(config *cfg.Config, listenAddress string) { +func applyDevModeOverrides(config *cfg.Config, runtimeConfig *Config) { config.CSP.ScriptSrc = slices.Insert(config.CSP.ScriptSrc, 0, "'unsafe-inline'") config.CSP.ConnectSrc = slices.Insert(config.CSP.ConnectSrc, 0, "'self'") + if runtimeConfig.Domains != "" { + config.Domains = strings.Split(runtimeConfig.Domains, ",") + } else { + config.Domains = []string{runtimeConfig.ListenAddress} + } config.BaseURL = cfg.URL{ URL: &url.URL{ Scheme: "http", - Host: listenAddress, + Host: runtimeConfig.ListenAddress, }, } } @@ -110,7 +119,7 @@ func New(runtimeConfig *Config) (*Server, error) { return nil, errors.WithMessage(err, "error parsing configuration file") } if runtimeConfig.Development { - applyDevModeOverrides(config, runtimeConfig.ListenAddress) + applyDevModeOverrides(config, runtimeConfig) } listenAddress := net.JoinHostPort(runtimeConfig.ListenAddress, strconv.Itoa(runtimeConfig.Port)) |