Persistent CORS Issues and 502 Errors on Railway Deployment

zoeytabmediaHOBBY

10 months ago

We're facing CORS problems and 502 errors with our Railway-hosted app, despite open CORS configuration.

Setup

  • Node.js/Express backend on Railway

  • Needs CORS access for all origins

Issue

  1. Server sets CORS headers (app.use(cors()))

  2. Clients get CORS errors + 502 Bad Gateway

  3. Works locally with ngrok, fails on Railway

![CORS and 502 Errors]
See image.

Key Points

  • CORS headers set but not received by clients

  • Need open CORS for multiple client websites

  • 502 errors suggest infrastructure problems

Questions

  1. Why are CORS headers possibly being stripped?

  2. Cause of 502 Bad Gateway errors?

  3. Railway-specific config needed for open CORS?

  4. How to ensure API accessibility from any origin?

We've verified server config, tested various CORS setups, and checked logs. Issue persists across browsers/devices.

Any insights on why headers might be stripped or requests failing with 502 would be greatly appreciated. Happy to provide more info if needed.

Thanks for your help!

0 Replies

zoeytabmediaHOBBY

10 months ago

b1a874f5-6306-4f25-887a-f8f72c50aa76


10 months ago

what happens when you simply open the public domain in a browser


10 months ago

public domain of your api


zoeytabmediaHOBBY

10 months ago

it displays the default response I set for the root endpoint


zoeytabmediaHOBBY

10 months ago

Like so


zoeytabmediaHOBBY

10 months ago

1271207910357205000


10 months ago

and what happens if you open the problematic link that is returning cors issues?


zoeytabmediaHOBBY

10 months ago

One moment, I’m not on my laptop right now, but I do have that response somewhere


zoeytabmediaHOBBY

10 months ago

It doesn’t seem to give the response I had earlier, I’ll have a look later @Brody


zoeytabmediaHOBBY

10 months ago

@Brody upstream connect error or disconnect/reset before headers. reset reason: protocol error


zoeytabmediaHOBBY

10 months ago

But I do have to say that's for the GET request in the browser, I'll have a look what POST request in Postman tells me


zoeytabmediaHOBBY

10 months ago

Oh actually it has to be a GET request, so this is where it fails


10 months ago

yep this would be an issue with your application returning an error that just doesn't have cors headers set on the error, I would recommend adding verbose logging so you can narrow down the issue


zoeytabmediaHOBBY

10 months ago

I noticed, currently fixing it


zoeytabmediaHOBBY

10 months ago

This issue has been fixed, for the people seeing this because they have the same error. It's most likely the way and the order you handle your routes.


10 months ago

glad you where able to solve it, thanks for the update!


Persistent CORS Issues and 502 Errors on Railway Deployment - Railway Help Station