- server.go now accepts configPath so setup mutation writes config.json to disk - setup mutation parses GraphQL variables and persists config — no more setup loop - request logger middleware logs every HTTP request with method/path/status/duration - GraphQL handler logs operation name and setup/status decisions - spaHandler simplified: serves real files directly, falls back to index.html only for paths that don't exist (fixes potential asset-serving issues) - health endpoint returns JSON and 503 in setup mode - main.go logs config path, storage path and db path on startup Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
47 lines
973 B
Go
47 lines
973 B
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/brasse-b/archivum/internal/config"
|
|
"github.com/brasse-b/archivum/internal/graph"
|
|
)
|
|
|
|
func main() {
|
|
cfgPath := configPath()
|
|
log.Printf("config path: %s", cfgPath)
|
|
|
|
cfg, err := config.Load(cfgPath)
|
|
if err != nil {
|
|
if errors.Is(err, config.ErrRequireSetup) {
|
|
log.Printf("no config found — starting in setup mode (wizard at http://localhost:4000/)")
|
|
} else {
|
|
log.Fatalf("failed to load config: %v", err)
|
|
}
|
|
} else {
|
|
log.Printf("config loaded — storage: %s db: %s", cfg.StoragePath, cfg.DBPath)
|
|
}
|
|
|
|
addr := ":4000"
|
|
if cfg != nil && cfg.ListenAddr != "" {
|
|
addr = cfg.ListenAddr
|
|
}
|
|
|
|
srv := graph.NewServer(cfg, cfgPath)
|
|
|
|
log.Printf("Archivum listening on %s", addr)
|
|
if err := http.ListenAndServe(addr, srv); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func configPath() string {
|
|
if p := os.Getenv("DOCKER_PATH"); p != "" {
|
|
return p + "/config/config.json"
|
|
}
|
|
return "config.json"
|
|
}
|