fix: server starts even without config (REQUIRE_SETUP mode)

main.go no longer fatals on ErrRequireSetup — it passes cfg=nil to NewServer.
NewServer returns REQUIRE_SETUP on every GraphQL call when cfg is nil, and
also adds CORS headers and serves the Vue SPA from /srv/archivum/ui.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-10 13:25:23 +02:00
parent 3e41191f45
commit 87821e8988
2 changed files with 31 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"errors"
"log"
"net/http"
"os"
@@ -11,14 +12,20 @@ import (
func main() {
cfg, err := config.Load(configPath())
if err != nil {
if err != nil && !errors.Is(err, config.ErrRequireSetup) {
log.Fatalf("failed to load config: %v", err)
}
// cfg may be nil when REQUIRE_SETUP — NewServer handles that gracefully.
addr := ":4000"
if cfg != nil && cfg.ListenAddr != "" {
addr = cfg.ListenAddr
}
srv := graph.NewServer(cfg)
log.Printf("Archivum listening on %s", cfg.ListenAddr)
if err := http.ListenAndServe(cfg.ListenAddr, srv); err != nil {
log.Printf("Archivum listening on %s", addr)
if err := http.ListenAndServe(addr, srv); err != nil {
log.Fatal(err)
}
}