ok
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
import 'dotenv/config';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import fs from 'fs';
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
import { createClient } from '@supabase/supabase-js';
|
||||
import * as decksApi from '../src/lib/api/decks-core.js';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const projectRoot = path.resolve(__dirname, '..');
|
||||
const distPath = path.join(projectRoot, 'dist');
|
||||
|
||||
const app = express();
|
||||
app.use(cors({ origin: true, credentials: true }));
|
||||
app.use(express.json());
|
||||
@@ -358,7 +365,21 @@ app.delete('/api/decks/:id', requireAuth, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Serve built frontend when dist/ exists (production)
|
||||
if (fs.existsSync(distPath)) {
|
||||
app.use(express.static(distPath));
|
||||
app.get('*', (req, res, next) => {
|
||||
if (req.path.startsWith('/api')) return next();
|
||||
res.sendFile(path.join(distPath, 'index.html'), (err) => {
|
||||
if (err) next(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const PORT = process.env.PORT || 3001;
|
||||
app.listen(PORT, () => {
|
||||
console.log(`API server listening on http://localhost:${PORT}`);
|
||||
if (fs.existsSync(distPath)) {
|
||||
console.log(`Serving frontend from dist/ (open http://localhost:${PORT})`);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user