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:
@@ -7,22 +7,38 @@ import (
|
||||
)
|
||||
|
||||
// NewServer wires up the HTTP handler for the GraphQL endpoint.
|
||||
// Replace the stub handler with the gqlgen-generated handler once
|
||||
// `go generate ./...` has been run.
|
||||
// cfg may be nil when the system has not been configured yet; in that case
|
||||
// every GraphQL request returns {"data":{"systemStatus":"REQUIRE_SETUP"}} so
|
||||
// the frontend can redirect to the Setup Wizard.
|
||||
func NewServer(cfg *config.Config) http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
// Placeholder — replace with generated gqlgen handler.
|
||||
mux.HandleFunc("/graphql", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||
if r.Method == http.MethodOptions {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
if cfg == nil {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write([]byte(`{"data":{"systemStatus":"REQUIRE_SETUP"}}`))
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: replace with gqlgen handler once generated.
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write([]byte(`{"data":{"systemStatus":"REQUIRE_SETUP"}}`))
|
||||
_, _ = w.Write([]byte(`{"data":{"systemStatus":"OK"}}`))
|
||||
})
|
||||
|
||||
// Simple health check.
|
||||
mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
|
||||
// Serve the embedded Vue SPA for every other path.
|
||||
mux.Handle("/", http.FileServer(http.Dir("/srv/archivum/ui")))
|
||||
|
||||
return mux
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user