-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (25 loc) · 836 Bytes
/
index.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
// index.js
const express = require('express');
const path = require('path');
const app = express();
const port = process.env.PORT || 3000;
// Serve static files (like index.html)
app.use(express.static(path.join(__dirname, 'public'), { etag: false, maxAge: 0 }));
// Define a route to serve index.html
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
app.get('/about', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'about.html'));
});
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'public', '404.html'));
});
// Example API endpoint
app.get('/api/message', (req, res) => {
res.json({ message: 'Hello from the server!' });
});
// Start server
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});