Skip to content

Commit

Permalink
added static file handle to framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Wilson committed Apr 30, 2012
1 parent d7ffefb commit 82e2013
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions index.js
@@ -1,11 +1,17 @@
var pin = require('linchpin'),
url = require('url'),
http = require('http'),
filed = require('filed'),
parseBody = require('./lib/parse'),
setResource = require('./lib/resource'),
mime = require('./lib/mime'),
log = require('./lib/log');

// find file if route not handled
pin.on('*', function(req, res) {
if(!req.handled) { filed('./public' + req.url).pipe(res); }
});

function Apprentice() {
var self = this;

Expand All @@ -15,12 +21,14 @@ function Apprentice() {
var path = url.parse(req.url).pathname, route = req.method;

res.text = function(body, statusCode) {
req.handled = true;
if (statusCode == null || statusCode == 'undefined') { statusCode = 200 };
res.writeHead(statusCode, { 'content-type': mime.text });
res.end(body);
}

res.json = function(body, statusCode) {
req.handled = true;
if (statusCode == null || statusCode == 'undefined') { statusCode = 200 };
try {
body = JSON.stringify(body);
Expand All @@ -34,6 +42,7 @@ function Apprentice() {
}

res.html = function(body, statusCode) {
req.handled = true;
if (statusCode == null || statusCode == 'undefined') { statusCode = 200 };
res.writeHead(statusCode, {'content-type': mime.html });
res.end(body);
Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -2,7 +2,7 @@
"author": "Tom Wilson <tom@jackhq.com>",
"name": "apprentice",
"description": "[Experimental] web library that adds some sugar to routing",
"version": "0.2.7",
"version": "0.2.8",
"repository": {
"url": ""
},
Expand All @@ -11,7 +11,8 @@
},
"dependencies": {
"linchpin": "0.2.1",
"qs": "~0.4.2"
"qs": "~0.4.2",
"filed": "0.0.6"
},
"devDependencies": {
"request": "~2.9.202",
Expand Down

0 comments on commit 82e2013

Please sign in to comment.