forked from henryhobhouse/project_byoman
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (23 loc) · 845 Bytes
/
Copy pathserver.js
File metadata and controls
27 lines (23 loc) · 845 Bytes
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
var http = require('http');
var url = require('url');
var ecstatic = require('ecstatic')({ root: __dirname + '/app/public' });
function start(route, handle) {
function onRequest(request, response) {
var pathname = url.parse(request.url).pathname;
console.log('request for ' + pathname + ' received!'); // eslint-disable-line
if ( pathname.substring(0, 4) == '/js/' ||
pathname.substring(0, 5) == '/css/' ||
pathname.substring(0, 5) == '/img/' ||
pathname == '/favicon.ico'){
ecstatic(request, response);
} else {
route(handle, pathname, response);
}
}
var server = http.createServer(onRequest);
var port = process.env.PORT || 3000;
server.listen(port, function() {
console.log("App is running on port " + port);// eslint-disable-line
});
}
exports.start = start;