502 Bad Gateway on preflight OPTIONS requests for stable, healthy service

kdoglad
PRO

22 days ago

I am experiencing a persistent 502 Bad Gateway error on all preflight OPTIONS requests to my Node.js/Express service, which is preventing my front-end application from functioning.

Evidence:

  1. My service is stable and healthy. The deployment logs confirm that the application starts successfully, connects to the database, and responds to the /health check path as expected.

    • Deployment Log:

      [INFO] Application starting...
      [INFO] Database pool created successfully.
      [INFO] Server is running on http://0.0.0.0:8080
      
  2. The error only occurs on preflight OPTIONS requests from the browser. The attached HTTP log shows the OPTIONS request to /auth/login failing with a 502 status after a 10-second timeout.

    • HTTP Log Snippet:

      method: "OPTIONS"
      path: "/auth/login"
      httpStatus: 502
      totalDuration: 10575
      
  3. The request never reaches my application. My application code includes detailed logging for all incoming requests, and the OPTIONS request from the browser never appears in the deployment logs.

This evidence strongly indicates that the issue is with the Railway proxy/gateway layer, which is not correctly forwarding these specific preflight requests to my running container.

Why is the proxy is returning a 502 error for these requests instead of routing them to my healthy service?

Awaiting User Response

2 Replies

Railway
BOT

22 days ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


22 days ago

Hello,

Even a simple GET request to the root of the application is returning a 502, so this is not isolated to preflight options requests.

Traffic is not being forwarded to your application because you have the target port set incorrectly, please see our docs on that topic -

https://docs.railway.com/reference/errors/application-failed-to-respond#target-port-set-to-the-incorrect-value

Best,

Brody


Status changed to Awaiting User Response Railway โ€ข 22 days ago


502 Bad Gateway on preflight OPTIONS requests for stable, healthy service - Railway Help Station