split containers
This commit is contained in:
@@ -2,6 +2,7 @@ import express from 'express';
|
||||
import cors from 'cors';
|
||||
import dotenv from 'dotenv';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { initDB } from './db/index.js';
|
||||
import authRoutes from './routes/auth.js';
|
||||
@@ -37,12 +38,24 @@ app.get('/api/health', (req, res) => {
|
||||
|
||||
// Serve static frontend files (for production)
|
||||
const frontendPath = path.join(__dirname, '../../frontend/dist');
|
||||
app.use(express.static(frontendPath));
|
||||
const frontendExists = fs.existsSync(frontendPath);
|
||||
|
||||
// Serve index.html for all non-API routes (SPA support)
|
||||
app.get('*', (req, res) => {
|
||||
res.sendFile(path.join(frontendPath, 'index.html'));
|
||||
});
|
||||
if (frontendExists) {
|
||||
app.use(express.static(frontendPath));
|
||||
|
||||
// Serve index.html for all non-API routes (SPA support)
|
||||
app.get('*', (req, res) => {
|
||||
res.sendFile(path.join(frontendPath, 'index.html'));
|
||||
});
|
||||
} else {
|
||||
console.log('ℹ️ Frontend dist not found - running in API-only mode (dev)');
|
||||
app.get('*', (req, res) => {
|
||||
res.json({
|
||||
message: "What's The Point API - Frontend running separately",
|
||||
frontend: "http://localhost:5173"
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const PORT = process.env.PORT || 4000;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user