Repository navigation
Fix/environment separation - #200
SanaBalaji208 wants to merge 12 commits into
Conversation
Wraps middlewareURL, stockfishServerURL, chessServerURL, and the Agora appId so they can be overridden at build time via REACT_APP_MIDDLEWARE_URL, REACT_APP_STOCKFISH_SERVER_URL, REACT_APP_CHESS_SERVER_URL, and REACT_APP_AGORA_APP_ID, falling back to the existing placeholder values when unset. Also adds productionType for parity with environment.js. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…imports The frontend build step wrote secrets to src/core/environments/environment.ts, a path nothing in the app imports, so MIDDLEWARE_URL/STOCKFISH_URL/CHESS_SERVER/ APP_ID never reached the built app. Replaced that dead step with REACT_APP_* env vars on the build step, which environment.prod.js now reads directly. Also adds a workflow_dispatch trigger so this workflow can be run manually against any branch going forward, without changing existing push/pull_request behavior. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Every consumer builds requests as `${middlewareURL}/path`, adding its own
leading slash. The placeholder fallbacks had a trailing slash too, which
would produce a double slash (e.g. middleware//auth/login) in any build
that reaches these fallbacks. Dropped the trailing slash to match the
no-trailing-slash convention every call site assumes.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Hey Sahana stockfishServer/src/index.js had wide-open CORS (origin: "*", app.use(cors())) — a real security hole. |
…ation # Conflicts: # stockfishServer/src/index.js
callback(new Error(...)) in the origin function makes cors call next(err), and no error-handling middleware is registered, so a mismatched Origin produced an unhandled 500 (with a leaked stack trace outside production) instead of just omitting CORS headers. Matches the callback(null, false) pattern already used in chessServer/stockfishServer. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
credentials: true was unconditional even when allowedOrigins includes "*", which is an unsafe combination (credentialed requests with a wildcard origin). Brings this in line with the equivalent guard already applied to stockfishServer: computes hasWildcard once and sets credentials: !hasWildcard. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Merge conflict resolved + two additional fixes from today's review pass Following up on the conflict flagged above — pulled main, resolved the conflict in stockfishServer/src/index.js, and pushed (a54ddbc). Also found and fixed two related issues while in there. Summary:
Both fixes pushed (77d6034, 9be2645). Full test counts unchanged from what's in the PR description (React 27/27, chessServer now 33/33 with the new test, stockfishServer 12/12, middlewareNode 204/204 with the new test) — no regressions from any of this. Separately flagged, not fixed here: sent Sahana a question about whether dropping chessClientURL from environment.prod.js was intentional (it looks like it was already dead/placeholder config tied to a TODO(merge-chessclient-refactor) comment in PlayStudent.tsx, not an active regression, but wanted to confirm before touching it). Logged as a follow-up, not blocking this PR: chessServer and stockfishServer each maintain their own copy of the CORS allowlist/wildcard logic — the duplication that let #199 and #200 collide in the first place. A real shared-module fix isn't trivial here since each service's Docker build context is scoped to its own directory (context: ../../chessServer, etc.), so it'd also mean restructuring the Docker build, not just the CORS code. Recommend scoping that as its own task rather than folding it into an already-large PR. |
|
Closing this in favor of a new PR with SSH-signed commits, since branch protection requires signed commits and these predate that being set up. |
Summary
Combines the frontend and backend environment-separation work into a single integration branch and fixes the cross-service configuration issues identified during end-to-end testing. This removes unsafe production localhost fallbacks, standardizes environment variable usage, improves production validation, and ensures the React frontend, middleware, ChessServer, StockfishServer, MongoDB, Apache proxy, and Socket.IO work together correctly.
Type of Change
Key Changes
REACT_APP_*configuration.ARG/ENVsupport so Create React App receives production service URLs during the build.REACT_APP_STOCKFISH_SERVER_URL..env.example.custom-environment-variables.jsonconfiguration.http://localhostandhttp://localhost:3000during local integrated testing through Apache.fix/frontend-environmentandfix/backend-environmentintofix/environment-separation.Testing
Testing completed:
/leaderboardAPI request passed.git diff --checkpassed.Bugs Fixed (if applicable)
localhostwhen required environment variables were missing.REACT_APP_STOCKFISH_URLandREACT_APP_STOCKFISH_SERVER_URL.http://localhostwas rejected by backend services.TODO (Follow-up Work)
Additional Notes
config/default.jscontains configuration structure and non-secret defaults only. Real production secrets are expected to be supplied through environment variables rather than committed configuration files.This PR intentionally combines both environment branches into one integration PR so the frontend and backend configuration changes are reviewed and validated together.