aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.net>2025-07-16 18:42:50 +0100
committerLeonardo Bishop <me@leonardobishop.net>2025-07-16 18:42:50 +0100
commit3af8911d46913b8e47c2bf18536a1ec4b7c21596 (patch)
tree51944840b5d12f2088ef9d0f982557e72d19205a /main.go
parent4c3e5c256930249798768b0195c42efca1428586 (diff)
Add systemd service files and fixes
Diffstat (limited to 'main.go')
-rw-r--r--main.go26
1 files changed, 15 insertions, 11 deletions
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())
}