about summary refs log tree commit diff stats
path: root/internal
diff options
context:
space:
mode:
authorAlan Pearce2024-06-25 18:02:18 +0200
committerAlan Pearce2024-06-25 18:09:28 +0200
commit398210c8ce4140de12720d3f16cc88284a146005 (patch)
tree2d8144b52870c97f8cd9b86738fd51b50cda0bf5 /internal
parentcd1125a213d742b5a89e8b60f0c7aafef13b8783 (diff)
downloadwebsite-398210c8ce4140de12720d3f16cc88284a146005.tar.lz
website-398210c8ce4140de12720d3f16cc88284a146005.tar.zst
website-398210c8ce4140de12720d3f16cc88284a146005.zip
build with ko instead of nix
Diffstat (limited to 'internal')
-rw-r--r--internal/server/server.go16
-rw-r--r--internal/server/tls.go2
2 files changed, 11 insertions, 7 deletions
diff --git a/internal/server/server.go b/internal/server/server.go
index e75efd3..556c660 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -8,6 +8,7 @@ import (
 	"net/url"
 	"os"
 	"slices"
+	"strconv"
 	"time"
 
 	"website/internal/builder"
@@ -34,14 +35,15 @@ type Config struct {
 	Root          string `conf:"default:website"`
 	Redirect      bool   `conf:"default:false"`
 	ListenAddress string `conf:"default:localhost"`
-	Port          string `conf:"default:3000,short:p"`
+	Port          int    `conf:"default:3000,short:p"`
+	TLSPort       int    `conf:"default:443"`
 	TLS           bool   `conf:"default:false"`
 }
 
 type Server struct {
 	*http.Server
-	config *cfg.Config
-	tls    bool
+	runtimeConfig *Config
+	config        *cfg.Config
 }
 
 func applyDevModeOverrides(config *cfg.Config, listenAddress string) {
@@ -108,7 +110,7 @@ func New(runtimeConfig *Config) (*Server, error) {
 		return nil, errors.WithMessage(err, "error parsing configuration file")
 	}
 
-	listenAddress := net.JoinHostPort(runtimeConfig.ListenAddress, runtimeConfig.Port)
+	listenAddress := net.JoinHostPort(runtimeConfig.ListenAddress, strconv.Itoa(runtimeConfig.Port))
 	top := http.NewServeMux()
 
 	if runtimeConfig.Development {
@@ -193,8 +195,8 @@ func New(runtimeConfig *Config) (*Server, error) {
 				},
 			), 0),
 		},
-		config: config,
-		tls:    runtimeConfig.TLS,
+		config:        config,
+		runtimeConfig: runtimeConfig,
 	}, nil
 }
 
@@ -207,7 +209,7 @@ func (s *Server) serve(tls bool) error {
 }
 
 func (s *Server) Start() error {
-	if err := s.serve(s.tls); err != http.ErrServerClosed {
+	if err := s.serve(s.runtimeConfig.TLS); err != http.ErrServerClosed {
 		return errors.Wrap(err, "error creating/closing server")
 	}
 
diff --git a/internal/server/tls.go b/internal/server/tls.go
index b60f474..afcaab6 100644
--- a/internal/server/tls.go
+++ b/internal/server/tls.go
@@ -42,6 +42,8 @@ func (s *Server) serveTLS() (err error) {
 
 	certmagic.DefaultACME.Agreed = true
 	certmagic.DefaultACME.Email = s.config.Email
+	certmagic.HTTPPort = s.runtimeConfig.Port
+	certmagic.HTTPSPort = s.runtimeConfig.TLSPort
 
 	return certmagic.HTTPS(s.config.Domains, s.Server.Handler)
 }