summaryrefslogtreecommitdiffstats
path: root/express/app3.js
diff options
context:
space:
mode:
Diffstat (limited to 'express/app3.js')
-rw-r--r--express/app3.js55
1 files changed, 55 insertions, 0 deletions
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);
+