24 lines
642 B
JavaScript
24 lines
642 B
JavaScript
// server.js
|
|
import express from "express";
|
|
import path from "path";
|
|
import { fileURLToPath } from "url";
|
|
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
// Fix __dirname in ES modules
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
// Serve static files from Vite build
|
|
app.use(express.static(path.join(__dirname, "dist")));
|
|
|
|
// React Router fallback: send index.html for any unmatched route
|
|
app.get(/.*/, (req, res) => {
|
|
res.sendFile(path.join(__dirname, "dist", "index.html"));
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`Server running at http://localhost:${PORT}`);
|
|
});
|