-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
33 lines (32 loc) · 1.11 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
const sleep = (time) => new Promise((resolve) => setTimeout(resolve, time));
require('http')
.createServer((req, res) => {
if (req.url === '/a') {
res.writeHead(200, { 'content-type': 'text/html' });
res.end(`
<!DOCTYPE html>
<head>
<link rel="shortcut icon" href="#" />
</head>
<body>
<script>
setTimeout(() => {
window.location.pathname = '/b';
}, 1000);
</script>
</body>
`);
} else if (req.url === '/b') {
sleep(1000).then(() => {
res.writeHead(200, { 'content-type': 'text/html' });
res.end(`
<!DOCTYPE html>
<head>
<link rel="shortcut icon" href="#" />
</head>
<body></body>
`);
});
} else res.destroy();
})
.listen(3000, () => console.log('http://localhost:3000'));