-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
50 lines (37 loc) · 1.42 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const express = require('express');
const path = require('path');
const app = express();
const port = 3000;
app.use(express.static('public'));
app.use(express.static('images'));
app.use(express.static('css'));
app.use(express.static('js'));
// Custom middleware to set Content-Type for .js files
const setJsContentType = (req, res, next) => {
if (req.path.endsWith('.js')) {
res.setHeader('Content-Type', 'application/javascript');
}
next();
};
// Serve static files from 'public' folder with custom headers
app.use('/public', setJsContentType, express.static(path.join(__dirname, 'public')));
// Serve static files from 'another' folder with custom headers
app.use('/pacman', setJsContentType, express.static(path.join(__dirname, 'pacman')));
app.use('/invaders', setJsContentType, express.static(path.join(__dirname, 'invaders')));
app.use('/pong', setJsContentType, express.static(path.join(__dirname, 'pong')));
//public static files
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
app.get('/pacman', (req, res) => {
res.sendFile(path.join(__dirname, 'pacman', 'index.html'));
});
app.get('/invaders', (req, res) => {
res.sendFile(path.join(__dirname, 'invaders', 'index.html'));
});
app.get('/pong', (req, res) => {
res.sendFile(path.join(__dirname, 'pong', 'index.html'));
});
app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
});