-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (38 loc) · 1.23 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
// FOR DEVELOPMENT PURPOSES ONLY!
const http = require('http');
const fs = require('fs');
const path = require('path');
const server = http.createServer((req, res) => {
const { url } = req;
let filePath;
if (url === '/') {
filePath = path.join(__dirname, 'htdocs', 'splash.html');
}
else if (url.startsWith('/$authaction?')) {
filePath = path.join(__dirname, 'htdocs', 'status.html');
}
else {
filePath = path.join(__dirname, 'htdocs', url);
}
fs.readFile(filePath, (err, data) => {
if (err) {
res.writeHead(404);
res.end('Not Found');
} else {
let contentType = 'text/html';
if (filePath.endsWith('.css')) {
contentType = 'text/css';
} else if (filePath.endsWith('.js')) {
contentType = 'text/javascript';
} else if (filePath.endsWith('.jpg') || filePath.endsWith('.jpeg')) {
contentType = 'image/jpeg';
}
res.writeHead(200, { 'Content-Type': contentType });
res.end(data);
}
});
});
const PORT = process.env.PORT || 3000;
server.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});