Skip to content

fix: read http-server CORS origin from CORS_ORIGIN - #217

Merged
TheCodeHeist-Coder merged 1 commit into
TheCodeHeist-Coder:mainfrom
Anshuu2004:fix/http-server-cors-origin-env
Oct 26, 2026
Merged

TheCodeHeist-Coder merged 1 commit into
TheCodeHeist-Coder:mainfrom
Anshuu2004:fix/http-server-cors-origin-env

Conversation

@Anshuu2004

Copy link
Copy Markdown
Contributor

What does this PR do?

The http-server had cors({ origin: 'https://rexial.in' }) hard-coded, so the frontend on localhost:5173 got blocked by CORS in local dev. It now reads the allowed origins from a CORS_ORIGIN env var (comma separated) and falls back to http://localhost:5173 when it is not set, same pattern as apps/streaming/src/config.ts.

I also added CORS_ORIGIN to the http-server .env example in setup.md and CONTRIBUTING.md.

Production needs CORS_ORIGIN=https://rexial.in set before this is deployed. .env.prod is gitignored so I could not add it myself. If it is missing, the server will only allow http://localhost:5173 and the live site will get CORS errors.

Related issue

Closes #212

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactoring
  • Performance
  • Tests
  • Build / CI / deployment

Which services does this touch?

  • apps/frontend
  • apps/http-server
  • apps/ws-server
  • apps/genAI
  • packages/db (schema or Prisma changes)
  • Docker / CI

How did you test this?

Built http-server (pnpm --filter http-server build, passes) and started node dist/index.js on a few ports. It starts fine without a database running. Then sent the preflight from the issue with curl:

curl -i -X OPTIONS localhost:<port>/api/v1/auth/login -H "Origin: <origin>" -H "Access-Control-Request-Method: POST" -H "Access-Control-Request-Headers: content-type"

  • CORS_ORIGIN unset: http://localhost:5173 gets Access-Control-Allow-Origin: http://localhost:5173.
  • CORS_ORIGIN=https://rexial.in: https://rexial.in is still allowed. http://localhost:5173 and https://evil.example get no Access-Control-Allow-Origin header.
  • CORS_ORIGIN="https://rexial.in, http://localhost:5173": both are allowed, https://evil.example is not.

I did not run it with the full docker compose stack or the real frontend in a browser.

Checklist

  • I ran pnpm run lint
  • I ran pnpm run check-types
  • I ran pnpm run build
  • The app still starts with docker-compose up
  • I updated documentation if this changes behaviour or setup
  • I did not commit any .env file, API key or other secret

pnpm run lint fails on main already, in apps/frontend (a bunch of no-explicit-any errors in files I did not touch), so I left that box unticked. pnpm run check-types passes, but http-server has no check-types script so it only covers other packages; tsc -b in the http-server build is what type-checked my change. I only ran the http-server build, not the full pnpm run build.


First pull request here? CONTRIBUTING.md walks through the
whole process, and a checkbox left unticked is not a problem — say so and we
will help.

The origin was hard-coded to https://rexial.in, so the frontend on
localhost:5173 got blocked in local dev. It now comes from a
comma-separated CORS_ORIGIN env var and defaults to
http://localhost:5173, same as apps/streaming.

Production needs CORS_ORIGIN=https://rexial.in in .env.prod.
@TheCodeHeist-Coder
TheCodeHeist-Coder self-requested a review October 26, 2026 12:46

@TheCodeHeist-Coder TheCodeHeist-Coder left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

@TheCodeHeist-Coder
TheCodeHeist-Coder merged commit 23dec08 into TheCodeHeist-Coder:main Oct 26, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Local dev is broken: http-server's CORS origin is hard coded to https://rexial.in, so every browser call from localhost:5173 is blocked

2 participants