Fix SAN Docker deployment: CORS and static file serving#182
Merged
spydmobile merged 6 commits intomainfrom Mar 2, 2026
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test plan
Closes #181