SIGN IN SIGN UP
2019-03-14 18:52:33 +03:00
let http = require('http');
let url = require('url');
let querystring = require('querystring');
let static = require('node-static');
let file = new static.Server('.');
2018-10-09 23:56:01 +03:00
function accept(req, res) {
2019-03-14 18:52:33 +03:00
if (req.url == '/load') {
2018-10-09 23:56:01 +03:00
res.writeHead(200, {
'Content-Type': 'text/plain',
2019-03-14 18:52:33 +03:00
'Cache-Control': 'no-cache',
'Content-Length': 90000
2018-10-09 23:56:01 +03:00
});
2019-03-14 18:52:33 +03:00
let i = 0;
2018-10-09 23:56:01 +03:00
2019-03-14 18:52:33 +03:00
let timer = setInterval(write, 1000);
2018-10-09 23:56:01 +03:00
write();
function write() {
2019-03-14 18:52:33 +03:00
res.write(String(i).repeat(10000));
i++;
2018-10-09 23:56:01 +03:00
if (i == 9) {
clearInterval(timer);
res.end();
}
}
2019-03-17 20:05:02 +03:00
} 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();
2018-10-09 23:56:01 +03:00
} else {
file.serve(req, res);
}
}
// ----- запуск accept как сервера из консоли или как модуля ------
if (!module.parent) {
http.createServer(accept).listen(8080);
} else {
exports.accept = accept;
2019-03-14 18:52:33 +03:00
}