(root, options)
| 11 | var version = [0, 7, 9]; |
| 12 | |
| 13 | var 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 | |
| 52 | Server.prototype.serveDir = function (pathname, req, res, finish) { |
| 53 | var htmlIndex = path.join(pathname, this.options.indexFile), |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…