-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
32 lines (26 loc) · 839 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import express from "express";
import { fileURLToPath } from "url";
import { dirname, extname } from "path";
import path from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const app = express();
// Serve static files from the 'dist' directory
app.use(express.static(path.join(__dirname, "dist")));
// Handle all other routes by serving the index.html file
app.get("/*", (req, res) => {
res.sendFile(path.join(__dirname, "dist", "index.html"));
});
// Set correct MIME type for JavaScript files
app.use((req, res, next) => {
const ext = extname(req.url);
if (ext === ".js") {
res.type("application/javascript");
}
next();
});
// Start the server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is listening on port ${PORT}`);
});