From 3af8911d46913b8e47c2bf18536a1ec4b7c21596 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Wed, 16 Jul 2025 18:42:50 +0100 Subject: Add systemd service files and fixes --- main.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 5be14da..8292649 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "fmt" "log/slog" "net/http" + "os" "path" "path/filepath" @@ -32,21 +33,16 @@ func main() { siteIndex := index.NewSiteIndex() - err = index.ScanDirectory(path.Join(constants.SysDataDir, "sites"), siteIndex) + sitesDirectory := path.Join(constants.SysDataDir, "sites") + os.MkdirAll(sitesDirectory, 0o755) + + err = index.ScanDirectory(sitesDirectory, siteIndex) if err != nil { panic(fmt.Errorf("could not scan data directory: %w", err)) } slog.Info("initial data directory scan complete", "sites", len(siteIndex.GetSites())) - if cfg.Command.Host == "" { - slog.Warn("command interface host is empty - neither api or web interface will be accessible") - } - - if cfg.Command.Secret == "" { - slog.Warn("command interface secret is empty - neither api or web interface will be accessible") - } - secretKey := make([]byte, 32) rand.Read(secretKey) @@ -54,10 +50,18 @@ func main() { mux := http.NewServeMux() - mux.Handle(fmt.Sprintf("%s/api/", cfg.Command.Host), http.StripPrefix("/api/", api.NewMux(&cfg, siteIndex))) - mux.Handle(fmt.Sprintf("%s/", cfg.Command.Host), web.NewMux(&cfg, siteIndex, authenticator)) + if cfg.Command.Host == "" { + slog.Warn("command interface host is empty - neither api or web interface will be accessible") + } else { + mux.Handle(fmt.Sprintf("%s/api/", cfg.Command.Host), http.StripPrefix("/api/", api.NewMux(&cfg, siteIndex))) + mux.Handle(fmt.Sprintf("%s/", cfg.Command.Host), web.NewMux(&cfg, siteIndex, authenticator)) + } mux.HandleFunc("/", server.ServeSite(siteIndex)) + if cfg.Command.Secret == "" { + slog.Warn("command interface secret is empty - neither api or web interface will be accessible") + } + err = http.ListenAndServe(fmt.Sprintf("%s:%d", cfg.Listen.Address, cfg.Listen.Port), mux) slog.Error("http server closing", "reason", err.Error()) } -- cgit v1.2.3-70-g09d2