fixes, translation
This commit is contained in:
parent
de4a68a58d
commit
596a24cba3
13 changed files with 755 additions and 252 deletions
42
7-network/1-xmlhttprequest/readystate.view/server.js
Normal file
42
7-network/1-xmlhttprequest/readystate.view/server.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
var http = require('http');
|
||||
var url = require('url');
|
||||
var querystring = require('querystring');
|
||||
var static = require('node-static');
|
||||
var file = new static.Server('.');
|
||||
|
||||
function accept(req, res) {
|
||||
|
||||
if (req.url == '/digits') {
|
||||
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/plain',
|
||||
'Cache-Control': 'no-cache'
|
||||
});
|
||||
|
||||
var i = 0;
|
||||
|
||||
var timer = setInterval(write, 1000);
|
||||
write();
|
||||
|
||||
function write() {
|
||||
res.write(new Array(1000).join(++i + '') + ' ');
|
||||
if (i == 9) {
|
||||
clearInterval(timer);
|
||||
res.end();
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
file.serve(req, res);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----- запуск accept как сервера из консоли или как модуля ------
|
||||
|
||||
if (!module.parent) {
|
||||
http.createServer(accept).listen(8080);
|
||||
} else {
|
||||
exports.accept = accept;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue