summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle K <kylek389@gmail.com>2012-06-30 17:36:04 -0500
committerKyle Kaminski <kyle@kkaminsk.com>2012-06-30 17:36:04 -0500
commitf052db6b797d7b2f08263ed39ced3c2095c4658d (patch)
treeb08022717ab5e9d0d5fc260eabc99dbefafd5e67
parentd795d12618bc816c547fc6fd50b167c481be9e22 (diff)
downloadfubar-f052db6b797d7b2f08263ed39ced3c2095c4658d.tar.gz
fubar-f052db6b797d7b2f08263ed39ced3c2095c4658d.tar.bz2
fubar-f052db6b797d7b2f08263ed39ced3c2095c4658d.zip
i'm not talking
-rw-r--r--express/app2.js9
-rw-r--r--express/app3.js55
-rw-r--r--public/foo.txt2
3 files changed, 58 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);
+
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