-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
26 lines (21 loc) · 817 Bytes
/
index.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
'use strict';
const http = require('http');
const url = require('url');
function createServer () {
const server = http.createServer((request, response) => {
if (url.parse(request.url).pathname === '/withDelay') {
response.writeHead(200, {'content-type': 'application-json'});
let currentTime = new Date().getTime();
while (currentTime + 5000 >= new Date().getTime()) { }
response.end('With delay.');
} else if (url.parse(request.url).pathname === '/withoutDelay') {
response.writeHead(200, {'content-type': 'application-json'});
response.end('Without delay.');
}
});
console.log('Endpoints:');
console.log('http://localhost:3000/withDelay');
console.log('http://localhost:3000/withoutDelay');
return server.listen(3000, 'localhost');
}
createServer();