-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (26 loc) · 809 Bytes
/
Copy pathserver.js
File metadata and controls
30 lines (26 loc) · 809 Bytes
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
const express = require('express');
const path = require('path');
const fs = require('fs');
// Create express application
const app = express();
const PORT = process.env.PORT || 4000;
const DIST_FOLDER = path.join(__dirname, 'docs');
// Serve static files from the docs folder
app.use(express.static(DIST_FOLDER));
// All routes serve the index.html file
app.get('*', (req, res) => {
const indexPath = path.join(DIST_FOLDER, 'index.html');
res.sendFile(indexPath, (err) => {
if (err) {
if (err.code === 'ENOENT') {
res.status(404).send('index.html file not found');
} else {
res.status(500).send('Error accessing index.html file');
}
}
});
});
// Start the server
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});