diff options
author | Kyle K <kylek389@gmail.com> | 2012-06-30 17:36:04 -0500 |
---|---|---|
committer | Kyle Kaminski <kyle@kkaminsk.com> | 2012-06-30 17:36:04 -0500 |
commit | f052db6b797d7b2f08263ed39ced3c2095c4658d (patch) | |
tree | b08022717ab5e9d0d5fc260eabc99dbefafd5e67 /express | |
parent | d795d12618bc816c547fc6fd50b167c481be9e22 (diff) | |
download | fubar-f052db6b797d7b2f08263ed39ced3c2095c4658d.tar.gz fubar-f052db6b797d7b2f08263ed39ced3c2095c4658d.tar.bz2 fubar-f052db6b797d7b2f08263ed39ced3c2095c4658d.zip |
i'm not talking
Diffstat (limited to 'express')
-rw-r--r-- | express/app2.js | 9 | ||||
-rw-r--r-- | express/app3.js | 55 |
2 files changed, 56 insertions, 8 deletions
diff --git a/express/app2.js b/express/app2.js index db95537..292741b 100644 --- a/express/app2.js +++ b/express/app2.js @@ -14,15 +14,8 @@ app.configure('dev', function() { app.configure(function() { app.use(express.logger('dev')); app.use(express.favicon()); - - app.use(express.methodOverride()); - /* parse request bodies, place the result in req.body */ - app.use(express.bodyParser()); app.use(app.router); - var oneYear = 31557600000; - app.use(express.static(__dirname + '/public', { maxAge: oneYear })); - - app.set('views', __dirname + '/views'); + /* empty, next() would lead us here */ }); app.get('/*', function(req, res, next) { diff --git a/express/app3.js b/express/app3.js new file mode 100644 index 0000000..1532b28 --- /dev/null +++ b/express/app3.js @@ -0,0 +1,55 @@ +/* + * diff: does simple error handling + * reqmnts: $ pacman -S redis and start daemon + */ + +var express = require('express'); +var util = require('util'); +var RedisStore = require('connect-redis')(express); + +var app = express.createServer() +var pagehits = 0; + +app.configure('dev', function() { + app.use(express.errorHandler({ + dumpExceptions: true, + showStack: true + })); +}); + +app.configure(function() { + app.use(express.logger('dev')); + app.use(express.favicon()); + app.use(express.methodOverride()); + /* parse request bodies, place the result in req.body */ + app.use(express.bodyParser()); + app.use(express.cookieParser()); + app.use(express.session({ secret: "keyboard cat", store: new RedisStore })); + /* should be on the bottom of this block? */ + app.use(app.router); + app.use(express.static(__dirname + '/public', { maxAge: 31557600000 /* one year */ })); + app.set('views', __dirname + '/views'); +}); + +app.get('/*', function(req, res, next) { + pagehits++; + next(); +}); +app.get('/info', function(req, res) { + res.send('page hits: ' + pagehits + '\n'); +}); +app.get('/', function(req, res) { + res.send('hello, world!\n'); +}); +app.get('/user/:id([0-9]+)', function(req, res) { + res.send('user ' + req.params.id); +}); +app.get('/*', function(req, res) { + throw new Error('the fuck you doing?!'); +}); +app.error(function(err, req, res, next) { + next(err); /* needs to be here or page load will stall on wrong pn */ +}); + +app.listen(8081); + |