server.js
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
// server.js
|
||||||
|
import express from "express";
|
||||||
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
const PORT = process.env.PORT || 3001;
|
||||||
|
|
||||||
|
// 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}`);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user