This repository was archived by the owner on Feb 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
54 lines (43 loc) · 1.2 KB
/
index.js
File metadata and controls
54 lines (43 loc) · 1.2 KB
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
var express = require('express');
var morgan = require('morgan');
var cookieParser = require('cookie-parser')
var bodyParser = require('body-parser')
var http = require('http');
const PORT = 7000;
const HOST = 'localhost';
const TIMEOUT = 0;
var app = express();
app.use(morgan('combined'));
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: false }));
var server = http.createServer(app);
function sleep(time) {
return new Promise((resolve, reject) => {
if (time < 0) {
reject('INVALID');
}
setTimeout(function() {
resolve();
}, time);
});
}
function handle(req, res) {
console.log('Headers: ', req.headers);
console.log('Cookies: ', req.cookies);
sleep(TIMEOUT).then(()=> {
res.cookie('kookie' , 'value', {});
res.send('OK');
}).catch((reason)=> {
res.send(reason);
})
}
app.get('/', function (req, res) {
handle(req, res);
})
app.post('/', function (req, res) {
handle(req, res);
})
server.listen(PORT, HOST);
server.on('listening', function() {
console.log('Express server started at http://%s:%s/', server.address().address, server.address().port);
});