en.javascript.info/4-ajax/6-xhr-onprogress/progress.view/server.js
2015-03-09 18:48:58 +03:00

38 lines
No EOL
814 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var http = require('http');
var url = require('url');
var querystring = require('querystring');
var static = require('node-static');
var file = new static.Server('.', {
cache: 0
});
function accept(req, res) {
if (req.url == '/upload') {
var length = 0;
req.on('data', function(chunk) {
// ничего не делаем с приходящими данными, просто считываем
length += chunk.length;
if (length > 50 * 1024 * 1024) {
res.statusCode = 413;
res.end("File too big");
}
}).on('end', function() {
res.end('ok');
});
} else {
file.serve(req, res);
}
}
// ------ запустить сервер -------
if (!module.parent) {
http.createServer(accept).listen(8080);
} else {
exports.accept = accept;
}