SPA routing fallback not working - all client-side routes return 404"
sales440
HOBBYOP

5 months ago

Hello Railway Support,

I'm experiencing an issue with my Node.js + Express + React SPA deployment where

client-side routes return 404 errors instead of serving the index.html file.

PROJECT DETAILS:

- Project Name: fagor-training-form

- Service Name: fagor-training-form-production

- Production URL: https://fagor-training-form-production.up.railway.app

- GitHub Repo: https://github.com/sales440/fagor-training-form

- Branch: main

ISSUE:

- Main route (/ ) works correctly

- All client-side routes return 404 (e.g., /admin/login, /admin/dashboard, /confirm-dates)

- The Express server has correct SPA fallback configuration

SERVER CONFIGURATION:

The server is configured to serve index.html for all routes:

File: server/_core/vite.ts (lines 64-66)

```typescript

app.use("*", (_req, res) => {

res.sendFile(path.resolve(distPath, "index.html"));

});

$10 Bounty

1 Replies

domehane
FREE

5 months ago

add express.static(distPath) BEFORE your catchall route. right now your app.use("*") is catching everything including your js/css files. add this before line 64:

typescript

app.use(express.static(path.resolve(distPath)));

express processes middleware in order, so static files need to be served first, then the catchall handles spa routes. that's why everything returns 404 - your catchall is intercepting your asset requests


Welcome!

Sign in to your Railway account to join the conversation.

Loading...