From f052db6b797d7b2f08263ed39ced3c2095c4658d Mon Sep 17 00:00:00 2001 From: Kyle K Date: Sat, 30 Jun 2012 17:36:04 -0500 Subject: i'm not talking --- express/app2.js | 9 +-------- express/app3.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ public/foo.txt | 2 ++ 3 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 express/app3.js create mode 100644 public/foo.txt 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); + diff --git a/public/foo.txt b/public/foo.txt new file mode 100644 index 0000000..d8c02ef --- /dev/null +++ b/public/foo.txt @@ -0,0 +1,2 @@ +this is a foo.txt file +2nd line -- cgit v1.2.3