@@ -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
0 commit comments