Permalink
Browse files

First commit!

  • Loading branch information...
jfhbrook committed Nov 16, 2011
0 parents commit 551617ed7a8ae5d70a5e0e0c78d94af5974ae446
Showing with 66 additions and 0 deletions.
  1. +30 −0 ecstatic.js
  2. +15 −0 example.js
  3. +20 −0 package.json
  4. +1 −0 public/hello.txt
  5. BIN public/turtle.png
@@ -0,0 +1,30 @@
var path = require("path"),
mime = require("mime"),
fs = require("fs");
module.exports = function (p) {
return function (req, res, next) {
// If there's a file, serve it up.
if (path.existsSync(p + req.url) && !fs.statSync(p + req.url).isDirectory()) {
fs.readFile(p + req.url, function (err, buff) {
if (err) {
console.log(err);
res.writeHead(500);
res.end();
return;
}
res.writeHead(200, { "Content-Type": mime.lookup(p + req.url) });
res.end(buff);
});
}
else {
// There's no file to return; Keep digging.
// Style decision here: calling 'next()' keeps backwards compat. with
// connect.
next();
}
};
}
@@ -0,0 +1,15 @@
var union = require("union"),
express = require("express"),
expressStatic = express.static(__dirname + '/public'),
ecstatic = require("./ecstatic")(__dirname + '/public');
union.createServer({
before: [
ecstatic
]
}).listen(8080);
express.createServer(ecstatic).listen(8081);
console.log("union: localhost:8080");
console.log("express: localhost:8081");
@@ -0,0 +1,20 @@
{
"author": "Joshua Holbrook <josh@nodejitsu.com> (http://jesusabdullah.net)",
"name": "ecstatic",
"description": "A simple static file server middleware that works with both Express and Flatiron",
"version": "0.0.0",
"homepage": "https://github.com/jesusabdullah/node-ecstatic",
"repository": {
"type": "git",
"url": "git@github.com:jesusabdullah/node-ecstatic.git"
},
"main": "./ecstatic.js",
"scripts": {
"test": "node example.js"
},
"engines": {
"node": "*"
},
"dependencies": {},
"devDependencies": {}
}
@@ -0,0 +1 @@
Hello world!
BIN +191 KB public/turtle.png
Binary file not shown.

0 comments on commit 551617e

Please sign in to comment.