This commit is contained in:
gitea
2026-03-07 15:10:37 +01:00
parent 84cb0ec0f6
commit aa3480af17
3 changed files with 32 additions and 1 deletions
+21
View File
@@ -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})`);
}
});