Skip to content

Commit 41dc6ef

Browse files
Fix Railway deployment: API-only mode, health check ready
1 parent dbd79d4 commit 41dc6ef

3 files changed

Lines changed: 56 additions & 17 deletions

File tree

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: cd server && npm start

server/app.ts

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,36 @@ export async function startServer() {
6565
// Register API routes
6666
const server = await registerRoutes(app);
6767

68-
// Serve static files in production
68+
// Serve static files in production (if available)
6969
if (process.env.NODE_ENV === 'production') {
7070
const distPath = path.join(process.cwd(), 'dist', 'public');
7171

72-
if (!fs.existsSync(distPath)) {
73-
console.error(`❌ Build directory not found: ${distPath}`);
74-
console.error('Run "npm run build" first!');
75-
process.exit(1);
72+
if (fs.existsSync(distPath)) {
73+
// Serve static assets
74+
app.use(express.static(distPath));
75+
76+
// SPA fallback - serve index.html for all non-API routes
77+
app.use('*', (_req, res) => {
78+
res.sendFile(path.join(distPath, 'index.html'));
79+
});
80+
81+
console.log('✅ Serving static files from dist/public');
82+
} else {
83+
console.log('ℹ️ No frontend build found - running API-only mode');
84+
console.log('ℹ️ This is normal for Railway backend deployment');
85+
86+
// Simple root endpoint for API-only mode
87+
app.get('/', (_req, res) => {
88+
res.json({
89+
message: 'Rug Killer API Server',
90+
status: 'online',
91+
endpoints: {
92+
health: '/api/health',
93+
docs: 'https://github.com/drixindustries/Rug-Killer-On-Solana'
94+
}
95+
});
96+
});
7697
}
77-
78-
// Serve static assets
79-
app.use(express.static(distPath));
80-
81-
// SPA fallback - serve index.html for all non-API routes
82-
app.use('*', (_req, res) => {
83-
res.sendFile(path.join(distPath, 'index.html'));
84-
});
85-
86-
console.log('✅ Serving static files from dist/public');
8798
} else {
8899
// Development mode - use Vite dev server
89100
try {
@@ -92,8 +103,21 @@ export async function startServer() {
92103
const { setupVite } = await import(viteDevPath);
93104
await setupVite(app, server);
94105
} catch (error: any) {
95-
console.error('❌ Failed to load Vite dev server (this is normal in production):', error.message);
96-
console.log('ℹ️ Running in production mode without Vite');
106+
console.warn('⚠️ Failed to load Vite dev server:', error.message);
107+
console.log('ℹ️ Running in API-only mode');
108+
109+
// Simple root endpoint for API-only mode
110+
app.get('/', (_req, res) => {
111+
res.json({
112+
message: 'Rug Killer API Server',
113+
status: 'online',
114+
mode: 'development',
115+
endpoints: {
116+
health: '/api/health',
117+
docs: 'https://github.com/drixindustries/Rug-Killer-On-Solana'
118+
}
119+
});
120+
});
97121
}
98122
}
99123

server/railway.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://railway.app/railway.schema.json",
3+
"build": {
4+
"builder": "NIXPACKS",
5+
"buildCommand": "cd server && npm install"
6+
},
7+
"deploy": {
8+
"startCommand": "cd server && npm start",
9+
"healthcheckPath": "/api/health",
10+
"healthcheckTimeout": 100,
11+
"restartPolicyType": "ON_FAILURE",
12+
"restartPolicyMaxRetries": 10
13+
}
14+
}

0 commit comments

Comments
 (0)