-
Notifications
You must be signed in to change notification settings - Fork 40
/
server.js
44 lines (30 loc) · 864 Bytes
/
server.js
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
var fs = require('fs');
var http = require('http');
var server = http.createServer(function(req, res) {
console.log(req.method + ' ' + req.url);
if (req.method === 'POST') {
var data = {
length: req.headers['content-length']
};
if (req.headers['x-requested-with'] === 'XMLHttpRequest') {
data['uploader'] = 'html5';
} else {
data['uploader'] = 'iframe';
}
req.on('data', function() {
});
console.log(data);
req.on('end', function() {
res.writeHead(200);
res.end(JSON.stringify(data));
});
} else {
req.addListener('end', function() {
var Server = require('node-static').Server;
var file = new Server(fs.realpathSync('.'));
file.serve(req, res);
}).resume();
}
});
console.log('View demo at http://localhost:8000/demo.html');
server.listen(8000);