Skip to content

Fix SAN Docker deployment: CORS and static file serving#182

Merged
spydmobile merged 6 commits intomainfrom
dev
Mar 2, 2026
Merged

Fix SAN Docker deployment: CORS and static file serving#182
spydmobile merged 6 commits intomainfrom
dev

Conversation

@spydmobile
Copy link
Contributor

Summary

Test plan

  • Verified static assets serve 200 via curl and browser
  • Verified model run POST returns 202 (not 500) with Origin header
  • Backend compiles clean (tsc)
  • Tested on sisko single-container Docker deployment

Closes #181

SpatialGeometry and TimeRange constructors threw plain Error instead of
ValidationError, causing the error handler to return 500 instead of 400
for invalid coordinates, unclosed polygon rings, and bad date ranges.

- Replace all validation throws with ValidationError in SpatialGeometry
- Replace all validation throws with ValidationError in TimeRange
- Add polygon ring-closing logic in frontend before submission
- Move geometry/time validation before DB writes to prevent orphaned records
In dev mode (NODE_ENV !== production), SAN CORS now allows requests from
the Vite dev server origin (localhost:VITE_DEV_PORT). Production behavior
unchanged — still blocks all cross-origin requests.
The .env ships with NODE_ENV=production (safe default for SAN mode CORS).
The dev script now overrides this at runtime so Vite dev server requests
are allowed through without weakening production CORS policy.
In SAN mode the backend serves the built frontend (same-origin).
The two-container setup broke this by putting frontend on :3901 and
backend on :4901, causing all relative API calls to miss the backend.

Dockerfile: 3-stage build (frontend, backend, production) places
frontend/dist at workspace-relative path so the backend static file
serving finds it automatically.

docker-compose: single nomad service replaces nomad-backend +
nomad-frontend, maps NOMAD_FRONTEND_HOST_PORT to backend port 3001.
Vite emits script type=module crossorigin which causes browsers to send
an Origin header even for same-origin requests. The SAN CORS policy blocks
all requests with an Origin header, returning 500 via the error handler.
Moving static file serving before CORS/auth middleware bypasses the issue
entirely -- static files do not need CORS checks.

Fixes #181
SAN is single-user on a trusted network with header-based auth (X-Nomad-User),
not cookie-based, so CORS provides no CSRF protection. The server also cannot
determine its external origin behind Docker port mapping (container :3001 vs
browser :3901). Browsers send Origin headers on same-origin POST/JSON requests
and on module script loads, which the old policy incorrectly blocked as
cross-origin, causing 500 errors on API calls and static assets.

ACN mode retains strict origin validation for multi-tenant deployments.
@spydmobile spydmobile merged commit 6a43701 into main Mar 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SAN Docker: Two-container setup breaks same-origin API calls

1 participant