-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_server.js
More file actions
33 lines (29 loc) · 922 Bytes
/
example_server.js
File metadata and controls
33 lines (29 loc) · 922 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
28
29
30
31
32
33
/**
* Author: Yakov Khalinsky (yakov@ninebyt.es)
* File: static.js
* Description: A simple implementation of a static file service for node.js
*/
var http = require("http");
var static = require("./lib/static.js");
/**
* An example custom function to deal with 404's returned by the static module
* You could use this to either provide a custom 404 or just fallback to other routes
*/
function notFoundErrors(req, res, code, message) {
console.log('running callback for not found errors:');
console.log(code + ': ' + message);
res.writeHead(code);
res.end(message);
return;
}
// initialise the static file server
static.init({
basePath : './public',
pathMatch : [ '/img', '/css', '/js', '/html' ],
errorMessage : '404 Not Found',
errorCallback : notFoundErrors,
logging : true
});
http.createServer(function (req, res) {
static.serve(req, res); // attempt to serve the static files
}).listen(1337);