-
Notifications
You must be signed in to change notification settings - Fork 14
/
server.mjs
56 lines (53 loc) · 1.53 KB
/
server.mjs
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
51
52
53
54
55
56
import { createServer } from 'http';
import { readFileSync } from 'fs';
const server = createServer((req, res) => {
console.log(`Receiving a request for ${req.url}`);
switch (req.url) {
case '/':
case '/index.html': {
res.writeHead(200, { 'Content-Type': 'text/html;charset=utf-8' });
res.end(readFileSync('./index.html'));
break;
}
case '/main.mjs': {
res.writeHead(200, { 'Content-Type': 'text/javascript;charset=utf-8' });
res.end(readFileSync('./main.mjs'));
break;
}
case '/data.json': {
res.writeHead(200, { 'Content-Type': 'application/json;charset=utf-8' });
res.end(readFileSync('./data.json'));
break;
}
case '/firefox-delta.json': {
res.writeHead(200, { 'Content-Type': 'application/json;charset=utf-8' });
res.end(readFileSync('./firefox-delta.json'));
break;
}
case '/firefox-failing.json': {
res.writeHead(200, { 'Content-Type': 'application/json;charset=utf-8' });
res.end(readFileSync('./firefox-failing.json'));
break;
}
case '/chrome-failing.json': {
res.writeHead(200, { 'Content-Type': 'application/json;charset=utf-8' });
res.end(readFileSync('./chrome-failing.json'));
break;
}
}
});
export const start = (port = 9001) => {
server.listen(port);
return new Promise((resolve) => {
server.on('listening', () => {
resolve();
});
});
};
export const stop = () => {
return new Promise((resolve) => {
server.close(() => {
resolve();
});
});
};