fixed server
This commit is contained in:
@@ -1,14 +1,20 @@
|
|||||||
|
// server.js
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
|
|
||||||
// Serve static files from dist
|
// 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")));
|
app.use(express.static(path.join(__dirname, "dist")));
|
||||||
|
|
||||||
// For React Router: always return index.html
|
// React Router fallback: send index.html for any unmatched route
|
||||||
app.get("*", (req, res) => {
|
app.get(/.*/, (req, res) => {
|
||||||
res.sendFile(path.join(__dirname, "dist", "index.html"));
|
res.sendFile(path.join(__dirname, "dist", "index.html"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user