-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (30 loc) · 754 Bytes
/
index.js
File metadata and controls
36 lines (30 loc) · 754 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
31
32
33
34
35
36
const {
readFileSync,
} = require('fs');
const {
createServer,
} = require('http');
const MAX = 3;
const PORT = process.env.PORT || 8080;
const FILES = Array.from({length: MAX}).map((_, idx) => readFileSync(`./logo/${idx}.png`));
const server = createServer((req, response) => {
if (req.url === '/logo.png') {
const file = FILES[Math.round(Math.random() * MAX)];
response.writeHead(200, {
'Content-Type': 'image/png',
'Expires': 'off',
});
response.end(file);
} else {
response.end(req.url);
}
});
server.listen(PORT, (err) => {
if (err) {
console.error('Failed:', err);
} else {
console.log(`Server started:`);
console.log(` - http://localhost:${PORT}/`);
console.log(` - http://truekit.openode.io/`)
}
});