This commit is contained in:
Ilya Kantor 2019-07-03 17:19:00 +03:00
parent 94c83e9e50
commit cc5213b09e
79 changed files with 1341 additions and 357 deletions

View file

@ -0,0 +1,52 @@
let http = require('http');
let url = require('url');
let querystring = require('querystring');
let static = require('node-static');
let file = new static.Server('.');
function accept(req, res) {
if (req.url == '/load') {
res.writeHead(200, {
'Content-Type': 'text/plain',
'Cache-Control': 'no-cache',
'Content-Length': 90000
});
let i = 0;
let timer = setInterval(write, 1000);
write();
function write() {
res.write(String(i).repeat(10000));
i++;
if (i == 9) {
clearInterval(timer);
res.end();
}
}
} else if (req.url == '/json') {
res.writeHead(200, {
// 'Content-Type': 'application/json;charset=utf-8',
'Cache-Control': 'no-cache'
});
res.write(JSON.stringify({message: "Hello, world!"}));
res.end();
} else {
file.serve(req, res);
}
}
// ----- запуск accept как сервера из консоли или как модуля ------
if (!module.parent) {
http.createServer(accept).listen(8080);
} else {
exports.accept = accept;
}