502 "Application failed to respond" — app starts successfully but proxy can't reach it
mihir3502
HOBBYOP

a month ago

Platform: Railway (Docker builder) Runtime: Node.js 20 / Express on Debian Bullseye Slim Database: SQLite via Prisma

What's happening: My backend deploys successfully and the logs confirm the app is running:

SAR backend running on port 3001

But every request through the Railway-provided domain returns a 502 "Application failed to respond" error.

My setup:

  • EXPOSE 3001 in Dockerfile
  • PORT=3001 set in Railway Variables
  • targetPort = 3001 in railway.toml
  • App binds to 0.0.0.0 explicitly: app.listen(3001, '0.0.0.0', ...)
  • startCommand = "npx prisma db push && node dist/index.js" in railway.toml

What I've tried:

  1. Set PORT=3001 as an explicit Railway Variable
  2. Added targetPort = 3001 to railway.toml [deploy]
  3. Changed app.listen() to explicitly bind to 0.0.0.0
  4. Tried baking startup into a start.sh script using exec node (PID 1) instead of startCommand
  5. Confirmed prisma db push succeeds in deploy logs before the app starts

Question: Is there something else Railway's edge proxy requires beyond targetPort, EXPOSE, and 0.0.0.0 binding? Could startCommand running as a shell chain (&&) prevent Railway from detecting the correct PID or port? Is there a way to view what port Railway's proxy is actually trying to connect to?

0 Replies

Welcome!

Sign in to your Railway account to join the conversation.

Loading...