Railway Service Serving Static Files Instead of Node.js API
journeydoc
HOBBYOP

6 months ago

Problem Summary

My Railway service is configured to run a Node.js Express API but is serving static files instead of executing my API routes. This is breaking my Facebook OAuth callback and all API endpoints.

Expected Behavior

  • Service should run my Node.js Express server

  • API routes like /api/auth/facebook/callback should execute server-side code

  • Should return JSON responses from my Express routes

Actual Behavior

  • API routes return HTML (React app's index.html) instead of executing Node.js code

  • Browser requests static assets after every API call

  • Network logs show Content-Type: text/html and Content-Disposition: inline; filename="index.html"

  • Call stack shows static file requests originating from API endpoints

Service Configuration

Build Command:cd backend && npm installStart Command:cd backend && node server.jsWatch Paths:

backend/**
!frontend/**
package.json

Evidence

  1. Server logs show Node.js starting correctly:

    INFO Accepting connections at http://localhost:3001
  2. But API calls trigger static file serving:

    GET /api/auth/facebook/callback → Returns 200 but serves index.html
    Followed by:
    GET /static/js/main.379b7289.js
    GET /static/css/main.94535c51.css
  3. Network inspector shows:

    • Status: 200 OK

    • Content-Type: text/html; charset=utf-8

    • Content-Disposition: inline; filename="index.html"

Repository Structure

project-root/
├── frontend/     (React app)
├── backend/      (Node.js Express API)
└── package.json

What I've Tried

  • Set correct build/start commands

  • Added watch paths to isolate backend

  • Verified server starts successfully

  • Railway still treats service as static site

Question

How can I force Railway to recognize this as a Node.js API service instead of a static site? It seems like Railway has "learned" to serve static files and won't switch back to running the Node.js server, even with correct configuration.

Service Name: whydiditdie-app-clean Service Type: Should be Node.js API, but behaving like static site

$10 Bounty

2 Replies

idiegea21
HOBBY

6 months ago

1. Go to Railway Dashboard

  • Open your Railway project

  • Click on your service (whydiditdie-app-clean)

2. Access Service Settings

  • Click on the Settings tab

  • Scroll down to find Source Repo section

3. Configure Root Directory

  • Find the Root Directory field

  • Set it to: backend

  • Click Save

4. Update Build & Start Commands

  • In the same Settings page, find Build Command

  • Set it to: npm install

  • Find Start Command

  • Set it to: node server.js

  • Click Save

5. Remove Watch Paths

  • Find Watch Paths section

  • Delete all watch paths (leave it empty)

  • Click Save

6. Force Redeploy

  • Go to Deployments tab

  • Click Deploy button to trigger a new deployment

After redeployment, your logs should show:

Building from backend directory...
Running: npm install
Running: node server.js
INFO Accepting connections at http://localhost:3001

And your API endpoints like /api/auth/facebook/callback will return JSON instead of HTML.


idiegea21

1. Go to Railway DashboardOpen your Railway projectClick on your service (whydiditdie-app-clean)2. Access Service SettingsClick on the Settings tabScroll down to find Source Repo section3. Configure Root DirectoryFind the Root Directory fieldSet it to: backendClick Save4. Update Build & Start CommandsIn the same Settings page, find Build CommandSet it to: npm installFind Start CommandSet it to: node server.jsClick Save5. Remove Watch PathsFind Watch Paths sectionDelete all watch paths (leave it empty)Click Save6. Force RedeployGo to Deployments tabClick Deploy button to trigger a new deploymentAfter redeployment, your logs should show:Building from backend directory... Running: npm install Running: node server.js INFO Accepting connections at http://localhost:3001And your API endpoints like /api/auth/facebook/callback will return JSON instead of HTML.

journeydoc
HOBBYOP

6 months ago

Thank you for your response, i truly appreciate it.

The issue seems more complex than i looks, i already had your suggestion in place, when i do finally figure it out, i'll update it here.


Loading...