Comparing version 0.1.2 to 0.1.4
@@ -14,3 +14,3 @@ var path = require('path'), | ||
var ecstatic = module.exports = function (dir, options) { | ||
var root = path.resolve(dir) + '/', | ||
var root = path.join(path.resolve(dir), '/'), | ||
opts = optsParser(options), | ||
@@ -46,2 +46,15 @@ cache = opts.cache, | ||
} | ||
else if(req.showDir) { | ||
// In this case, we were probably attempting to autoindex with | ||
// 'index.html' and it didn't work. This should prompt the | ||
// "showdir" function, which should've been set to `next`. | ||
// TODO: Re-evaluate this dependence on recursion. Could the confusion | ||
// introduced be eliminated? | ||
// TODO: We're attaching this random property to req to make it work, | ||
// which is BAD FORM. This *needs* a refactor but I think making it | ||
// not broken is the lesser of two evils. | ||
// NOTE: Alternate check here was: | ||
// `path.basename(req.url) === 'index.html' && autoIndex | ||
next(); | ||
} | ||
else { | ||
@@ -69,3 +82,4 @@ // Try for ./404.html | ||
middleware({ | ||
url: path.join(pathname, '/index.html') | ||
url: path.join(pathname, '/index.html'), | ||
showDir: true | ||
}, res, handler); | ||
@@ -82,3 +96,3 @@ } | ||
if ( req.headers | ||
&& ( (req.headers['if-none-match'] === etag) | ||
&& ( (req.headers['if-none-match'] === etag(stat)) | ||
|| (Date.parse(req.headers['if-none-match']) >= stat.mtime ) | ||
@@ -85,0 +99,0 @@ ) |
exports['304'] = function (res, next) { | ||
res.statusCode = 304; | ||
res.writeHead(304, res.headers); | ||
res.end(); | ||
@@ -7,9 +7,9 @@ }; | ||
exports['403'] = function (res, next) { | ||
if (next) { | ||
if (typeof next === "function") { | ||
next(); | ||
} | ||
else { | ||
res.statusCode = 403; | ||
if (res.writable) { | ||
res.setHeader('content-type', 'text/plain'); | ||
res.writeHead(403, res.headers); | ||
res.end('ACCESS DENIED'); | ||
@@ -21,5 +21,4 @@ } | ||
exports['405'] = function (res, next, opts) { | ||
res.statusCode = 405; | ||
res.setHeader('allow', (opts && opts.allow) || 'GET, HEAD'); | ||
res.writeHead(405, res.headers); | ||
res.end(); | ||
@@ -33,5 +32,5 @@ }; | ||
else { | ||
res.statusCode = 404; | ||
if (res.writable) { | ||
res.setHeader('content-type', 'text/plain'); | ||
res.writeHead(404, res.headers); | ||
res.end('File not found. :('); | ||
@@ -43,5 +42,5 @@ } | ||
exports['500'] = function (res, next, opts) { | ||
res.statusCode = 500; | ||
// TODO: Return nicer messages | ||
res.writeHead(500, res.headers); | ||
res.end(opts.error.stack || opts.error.toString() || "No specified error"); | ||
}; |
@@ -5,3 +5,3 @@ { | ||
"description": "A simple static file server middleware that works with both Express and Flatiron", | ||
"version": "0.1.2", | ||
"version": "0.1.4", | ||
"homepage": "https://github.com/jesusabdullah/node-ecstatic", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -15,3 +15,3 @@ # Ecstatic | ||
var express = require('express'); | ||
var ecstatic = require('../');; | ||
var ecstatic = require('ecstatic'); | ||
@@ -29,3 +29,3 @@ var app = express.createServer(); | ||
var union = require('union'); | ||
var ecstatic = require('../'); | ||
var ecstatic = require('ecstatic'); | ||
@@ -41,2 +41,21 @@ union.createServer({ | ||
## flatiron | ||
``` js | ||
var union = require('union'); | ||
var flatiron = require('flatiron'); | ||
var ecstatic = require('ecstatic'); | ||
app = new flatiron.App(); | ||
app.use(flatiron.plugins.http); | ||
app.http.before = [ | ||
ecstatic(__dirname + '/public') | ||
]; | ||
app.start(8080); | ||
console.log('Listening on :8080'); | ||
``` | ||
# API: | ||
@@ -43,0 +62,0 @@ |
209805
363
83