MCPcopy Index your code
hub / github.com/cloudhead/node-static / Server

Function Server

lib/node-static.js:13–50  ·  view source on GitHub ↗
(root, options)

Source from the content-addressed store, hash-verified

11var version = [0, 7, 9];
12
13var Server = function (root, options) {
14 if (root && (typeof(root) === 'object')) { options = root; root = null }
15
16 // resolve() doesn't normalize (to lowercase) drive letters on Windows
17 this.root = path.normalize(path.resolve(root || '.'));
18 this.options = options || {};
19 this.cache = 3600;
20
21 this.defaultHeaders = {};
22 this.options.headers = this.options.headers || {};
23
24 this.options.indexFile = this.options.indexFile || "index.html";
25
26 if ('cache' in this.options) {
27 if (typeof(this.options.cache) === 'number') {
28 this.cache = this.options.cache;
29 } else if (! this.options.cache) {
30 this.cache = false;
31 }
32 }
33
34 if ('serverInfo' in this.options) {
35 this.serverInfo = this.options.serverInfo.toString();
36 } else {
37 this.serverInfo = 'node-static/' + version.join('.');
38 }
39
40 this.defaultHeaders['server'] = this.serverInfo;
41
42 if (this.cache !== false) {
43 this.defaultHeaders['cache-control'] = 'max-age=' + this.cache;
44 }
45
46 for (var k in this.defaultHeaders) {
47 this.options.headers[k] = this.options.headers[k] ||
48 this.defaultHeaders[k];
49 }
50};
51
52Server.prototype.serveDir = function (pathname, req, res, finish) {
53 var htmlIndex = path.join(pathname, this.options.indexFile),

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…