fix: Railway deployment - add build script and SPA routing

This commit is contained in:
Anderson 2026-02-05 21:11:54 +00:00 committed by GitHub
parent f78681f3aa
commit 15123e8aa8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 11 deletions

View file

@ -11,6 +11,7 @@
"main": "src/backend/server.js", "main": "src/backend/server.js",
"scripts": { "scripts": {
"start": "node src/backend/server.js", "start": "node src/backend/server.js",
"build": "cd src/frontend && npm install && npm run build",
"dev": "nodemon src/backend/server.js", "dev": "nodemon src/backend/server.js",
"migrate": "node src/backend/database/migrate.js", "migrate": "node src/backend/database/migrate.js",
"test": "jest", "test": "jest",

14
railway.json Normal file
View file

@ -0,0 +1,14 @@
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"buildCommand": "npm run build"
},
"deploy": {
"startCommand": "npm start",
"healthcheckPath": "/health",
"healthcheckTimeout": 30,
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 3
}
}

View file

@ -47,11 +47,9 @@ app.get('/health', (req, res) => {
res.json({ status: 'ok', timestamp: new Date().toISOString() }); res.json({ status: 'ok', timestamp: new Date().toISOString() });
}); });
// Serve Astro build as main site // Serve React frontend build
app.use(express.static(path.join(__dirname, '../../astro-site/dist'))); const frontendPath = path.join(__dirname, '../frontend/dist');
app.use(express.static(frontendPath));
// Serve React app at /app
app.use('/app', express.static(path.join(__dirname, '../frontend/dist')));
// API routes // API routes
app.use('/api/passport/domain', domainRoutes); app.use('/api/passport/domain', domainRoutes);
@ -63,12 +61,16 @@ app.use('/api/calls', callRoutes);
const io = socketService.initialize(httpServer); const io = socketService.initialize(httpServer);
app.set('io', io); // Make io available in routes app.set('io', io); // Make io available in routes
// 404 handler // SPA fallback - serve index.html for all non-API routes (React Router)
app.use((req, res) => { app.get('*', (req, res) => {
res.status(404).json({ // Don't serve index.html for API routes
if (req.path.startsWith('/api/')) {
return res.status(404).json({
success: false, success: false,
error: 'Endpoint not found' error: 'Endpoint not found'
}); });
}
res.sendFile(path.join(__dirname, '../frontend/dist/index.html'));
}); });
// Error handler // Error handler