fix: Railway deployment - add build script and SPA routing
This commit is contained in:
parent
f78681f3aa
commit
15123e8aa8
3 changed files with 28 additions and 11 deletions
|
|
@ -11,6 +11,7 @@
|
|||
"main": "src/backend/server.js",
|
||||
"scripts": {
|
||||
"start": "node src/backend/server.js",
|
||||
"build": "cd src/frontend && npm install && npm run build",
|
||||
"dev": "nodemon src/backend/server.js",
|
||||
"migrate": "node src/backend/database/migrate.js",
|
||||
"test": "jest",
|
||||
|
|
|
|||
14
railway.json
Normal file
14
railway.json
Normal 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
|
||||
}
|
||||
}
|
||||
|
|
@ -47,11 +47,9 @@ app.get('/health', (req, res) => {
|
|||
res.json({ status: 'ok', timestamp: new Date().toISOString() });
|
||||
});
|
||||
|
||||
// Serve Astro build as main site
|
||||
app.use(express.static(path.join(__dirname, '../../astro-site/dist')));
|
||||
|
||||
// Serve React app at /app
|
||||
app.use('/app', express.static(path.join(__dirname, '../frontend/dist')));
|
||||
// Serve React frontend build
|
||||
const frontendPath = path.join(__dirname, '../frontend/dist');
|
||||
app.use(express.static(frontendPath));
|
||||
|
||||
// API routes
|
||||
app.use('/api/passport/domain', domainRoutes);
|
||||
|
|
@ -63,12 +61,16 @@ app.use('/api/calls', callRoutes);
|
|||
const io = socketService.initialize(httpServer);
|
||||
app.set('io', io); // Make io available in routes
|
||||
|
||||
// 404 handler
|
||||
app.use((req, res) => {
|
||||
res.status(404).json({
|
||||
// SPA fallback - serve index.html for all non-API routes (React Router)
|
||||
app.get('*', (req, res) => {
|
||||
// Don't serve index.html for API routes
|
||||
if (req.path.startsWith('/api/')) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
error: 'Endpoint not found'
|
||||
});
|
||||
}
|
||||
res.sendFile(path.join(__dirname, '../frontend/dist/index.html'));
|
||||
});
|
||||
|
||||
// Error handler
|
||||
|
|
|
|||
Loading…
Reference in a new issue