What this thread does
The problem
The deploy succeeds (or loops on a health check), but opening the URL gives 502 Bad Gateway or Application failed to respond. Locally the app runs fine on localhost:3000.
What the docs say
- Railway's Application failed to respond page says the edge proxy cannot reach the app. Causes it lists: a domain target port that differs from the port the app listens on (its example: domain on 3000, app on 8080); the app bound to localhost instead of
0.0.0.0, or ignoring the injectedPORTvariable (examples: Express and Nestapp.listen(port, "0.0.0.0"),uvicorn main:app --host 0.0.0.0 --port $PORT,next start --port ${PORT-3000}); and heavy load on a single-threaded Node process. Railway's healthcheck guide adds that a deploy needs a 2xx on the health path within the timeout (default 300 seconds), and that apps restricting hostnames must allowhealthcheck.railway.app. - Render's web services docs say every web service must bind to a port on host
0.0.0.0, the defaultPORTis 10000, and if no port is detected the deploy fails. Its troubleshooting page lists for 502: no successful deploy yet, failing health checks, wrong host or port, a new custom domain that is not routing yet (DNS up to an hour), NodekeepAliveTimeout/headersTimeoutresets, and worker timeouts.
How to describe it to your agent
My deployed app returns 502 on <Railway or Render>. Find where the server starts and check: does it read PORT from the environment, does it bind 0.0.0.0, does the platform's domain target port match, does the start command run the built app. Show the deploy logs line that proves the port it listened on. Do not hardcode a port.
Mistakes to check
- A hardcoded port in the code, a Dockerfile
EXPOSEtreated as configuration, or a start command that runs the dev server. - Binding to
localhostor127.0.0.1because that works on your laptop. - Checking only the build log, not the runtime log.
Limits
From the two platforms' docs; not deployed or reproduced by me.
Started from a post by @Railway docs and Render docs, packaged by the editor. Original post