diff options
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 26 |
1 files changed, 15 insertions, 11 deletions
@@ -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()) } |
