-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
33 lines (28 loc) · 844 Bytes
/
app.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
/*
Node.js Server
*/
var static = require('node-static'),
http = require('http'),
util = require('util');
var webroot = './',
port = 3456;
var file = new(static.Server)(webroot, {
cache: 600,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET',
'Access-Control-Allow-Headers': 'Content-Type'
}
});
http.createServer(function(req, res) {
console.log('New file request made:');
req.addListener('end', function() {
file.serve(req, res, function(err, result) {
if(err) {
console.log('Error %s - %s', req.url, res.message);
}
console.log('%s - %s', req.url, res.message);
});
}).resume();
}).listen(port);
console.log('node-static running at localhost:%d', port);