node-static
Advanced tools
Comparing version 0.7.7 to 0.7.8
@@ -43,2 +43,10 @@ #!/usr/bin/env node | ||
}) | ||
.option('spa', { | ||
description: 'serve the content as a single page app by redirecting all non-file requests to the index html file' | ||
}) | ||
.option('indexFile', { | ||
alias: 'i', | ||
'default': 'index.html', | ||
description: 'specify a custom index file when serving up directories' | ||
}) | ||
.option('help', { | ||
@@ -69,3 +77,3 @@ alias: 'h', | ||
if (argv.help){ | ||
if (argv.help) { | ||
require('optimist').showHelp(console.log); | ||
@@ -75,3 +83,3 @@ process.exit(0); | ||
if (argv.version){ | ||
if (argv.version) { | ||
console.log('node-static', statik.version.join('.')); | ||
@@ -81,11 +89,11 @@ process.exit(0); | ||
if (argv.cache){ | ||
if (argv.cache) { | ||
(options = options || {}).cache = argv.cache; | ||
} | ||
if (argv.headers){ | ||
if (argv.headers) { | ||
(options = options || {}).headers = JSON.parse(argv.headers); | ||
} | ||
if (argv['header-file']){ | ||
if (argv['header-file']) { | ||
(options = options || {}).headers = | ||
@@ -95,6 +103,10 @@ JSON.parse(fs.readFileSync(argv['header-file'])); | ||
if (argv.gzip){ | ||
if (argv.gzip) { | ||
(options = options || {}).gzip = true; | ||
} | ||
if (argv.indexFile) { | ||
(options = options || {}).indexFile = argv['indexFile']; | ||
} | ||
file = new(statik.Server)(dir, options); | ||
@@ -104,11 +116,17 @@ | ||
request.addListener('end', function () { | ||
file.serve(request, response, function(e, rsp) { | ||
if (e && e.status === 404) { | ||
response.writeHead(e.status, e.headers); | ||
response.end("Not Found"); | ||
log(request, response); | ||
} else { | ||
log(request, response); | ||
} | ||
}); | ||
var callback = function(e, rsp) { | ||
if (e && e.status === 404) { | ||
response.writeHead(e.status, e.headers); | ||
response.end("Not Found"); | ||
log(request, response); | ||
} else { | ||
log(request, response); | ||
} | ||
}; | ||
if (argv['spa'] && request.url.indexOf(".") !== -1) { | ||
file.serveFile(argv['indexFile'], 500, {}, request, response); | ||
} else { | ||
file.serve(request, response, callback); | ||
} | ||
}).resume(); | ||
@@ -118,1 +136,4 @@ }).listen(+argv.port, argv['host-address']); | ||
console.log('serving "' + dir + '" at http://' + argv['host-address'] + ':' + argv.port); | ||
if (argv.spa) { | ||
console.log('serving as a single page app (all non-file requests redirect to ' + argv['indexFile'] +')'); | ||
} |
@@ -258,3 +258,3 @@ var fs = require('fs') | ||
/* General byte range validation */ | ||
if (!isNaN(byteRange.from) && !!byteRange.to && 0 <= byteRange.from < byteRange.to) { | ||
if (!isNaN(byteRange.from) && !!byteRange.to && 0 <= byteRange.from && byteRange.from < byteRange.to) { | ||
byteRange.valid = true; | ||
@@ -340,3 +340,3 @@ } else { | ||
this.stream(key, files, new(buffer.Buffer)(length), startByte, res, function (e, buffer) { | ||
this.stream(key, files, length, startByte, res, function (e) { | ||
if (e) { return finish(500, {}) } | ||
@@ -360,3 +360,3 @@ finish(status, headers); | ||
Server.prototype.stream = function (pathname, files, buffer, startByte, res, callback) { | ||
Server.prototype.stream = function (pathname, files, length, startByte, res, callback) { | ||
@@ -374,8 +374,7 @@ (function streamFile(files, offset) { | ||
start: startByte, | ||
end: startByte + (buffer.length ? buffer.length - 1 : 0) | ||
end: startByte + (length ? length - 1 : 0) | ||
}).on('data', function (chunk) { | ||
// Bounds check the incoming chunk and offset, as copying | ||
// a buffer from an invalid offset will throw an error and crash | ||
if (chunk.length && offset < buffer.length && offset >= 0) { | ||
chunk.copy(buffer, offset); | ||
if (chunk.length && offset < length && offset >= 0) { | ||
offset += chunk.length; | ||
@@ -391,3 +390,3 @@ } | ||
res.end(); | ||
callback(null, buffer, offset); | ||
callback(null, offset); | ||
} | ||
@@ -394,0 +393,0 @@ })(files.slice(0), 0); |
@@ -37,3 +37,3 @@ { | ||
}, | ||
"version": "0.7.7", | ||
"version": "0.7.8", | ||
"engines": { | ||
@@ -40,0 +40,0 @@ "node": ">= 0.4.1" |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
42382
886
6