@@ -11,8 +11,11 @@ import fs from "fs";
1111export const app = express ( ) ;
1212
1313// Session middleware for wallet authentication
14+ const SESSION_SECRET = process . env . SESSION_SECRET || 'railway-fallback-secret-' + Date . now ( ) ;
15+ console . log ( '🔑 Using session secret:' , SESSION_SECRET . substring ( 0 , 10 ) + '...' ) ;
16+
1417app . use ( session ( {
15- secret : process . env . SESSION_SECRET || 'default-secret-change-in-production' ,
18+ secret : SESSION_SECRET ,
1619 resave : false ,
1720 saveUninitialized : false ,
1821 cookie : {
@@ -65,25 +68,36 @@ export async function startServer() {
6568 // Register API routes
6669 const server = await registerRoutes ( app ) ;
6770
68- // Serve static files in production
71+ // Serve static files in production (if available)
6972 if ( process . env . NODE_ENV === 'production' ) {
7073 const distPath = path . join ( process . cwd ( ) , 'dist' , 'public' ) ;
7174
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 ) ;
75+ if ( fs . existsSync ( distPath ) ) {
76+ // Serve static assets
77+ app . use ( express . static ( distPath ) ) ;
78+
79+ // SPA fallback - serve index.html for all non-API routes
80+ app . use ( '*' , ( _req , res ) => {
81+ res . sendFile ( path . join ( distPath , 'index.html' ) ) ;
82+ } ) ;
83+
84+ console . log ( '✅ Serving static files from dist/public' ) ;
85+ } else {
86+ console . log ( 'ℹ️ No frontend build found - running API-only mode' ) ;
87+ console . log ( 'ℹ️ This is normal for Railway backend deployment' ) ;
88+
89+ // Simple root endpoint for API-only mode
90+ app . get ( '/' , ( _req , res ) => {
91+ res . json ( {
92+ message : 'Rug Killer API Server' ,
93+ status : 'online' ,
94+ endpoints : {
95+ health : '/api/health' ,
96+ docs : 'https://github.com/drixindustries/Rug-Killer-On-Solana'
97+ }
98+ } ) ;
99+ } ) ;
76100 }
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' ) ;
87101 } else {
88102 // Development mode - use Vite dev server
89103 try {
@@ -92,8 +106,21 @@ export async function startServer() {
92106 const { setupVite } = await import ( viteDevPath ) ;
93107 await setupVite ( app , server ) ;
94108 } 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' ) ;
109+ console . warn ( '⚠️ Failed to load Vite dev server:' , error . message ) ;
110+ console . log ( 'ℹ️ Running in API-only mode' ) ;
111+
112+ // Simple root endpoint for API-only mode
113+ app . get ( '/' , ( _req , res ) => {
114+ res . json ( {
115+ message : 'Rug Killer API Server' ,
116+ status : 'online' ,
117+ mode : 'development' ,
118+ endpoints : {
119+ health : '/api/health' ,
120+ docs : 'https://github.com/drixindustries/Rug-Killer-On-Solana'
121+ }
122+ } ) ;
123+ } ) ;
97124 }
98125 }
99126
0 commit comments