Skip to content

Commit

Permalink
add bin/server.js as a bin
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Oct 16, 2012
1 parent 84401c5 commit 6c125cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.7",
"description": "A module for serving static files. Does etags, caching, etc.",
"main": "st.js",
"bin": "bin/server.js",
"dependencies": {
"lru-cache": "~2.0.0",
"mime": "~1.2.7",
Expand Down
6 changes: 6 additions & 0 deletions st.js
Expand Up @@ -210,12 +210,15 @@ Mount.prototype.serve = function (req, res, next) {
res.end()
return
}

res.setHeader('cache-control', 'public')
res.setHeader('last-modified', stat.mtime.toUTCString())
res.setHeader('etag', etag)

if (stat.isDirectory()) {
return this.index(p, req, res)
}

return this.file(p, fd, stat, etag, req, res)
}.bind(this));
}.bind(this));
Expand Down Expand Up @@ -306,6 +309,9 @@ Mount.prototype.streamFile = function (p, fd, stat, etag, req, res) {
var stream = fs.createReadStream(p, streamOpt)
stream.destroy = function () {}

// make sure it knows that we're using this right now.
streaming[p] = fd

// too late to effectively handle any errors.
// just kill the connection if that happens.
stream.on('error', function(e) {
Expand Down

0 comments on commit 6c125cd

Please sign in to comment.