-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple-server.js
More file actions
28 lines (25 loc) · 796 Bytes
/
simple-server.js
File metadata and controls
28 lines (25 loc) · 796 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
const http = require('http');
const fs = require('fs');
const path = require('path');
const port = 3000;
const gameFile = path.join(__dirname, 'super-mario-game', 'public', 'simple-mario.html');
const server = http.createServer((req, res) => {
if (req.url === '/' || req.url === '/simple-mario.html') {
fs.readFile(gameFile, (err, data) => {
if (err) {
res.writeHead(404);
res.end('Game file not found');
return;
}
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(data);
});
} else {
res.writeHead(404);
res.end('Not found');
}
});
server.listen(port, () => {
console.log(`Super Mario game server running at http://localhost:${port}`);
console.log('Open http://localhost:3000 in your browser to play!');
});