summaryrefslogtreecommitdiffstats
path: root/express
diff options
context:
space:
mode:
authorKyle K <kylek389@gmail.com>2012-06-30 14:30:41 -0500
committerKyle Kaminski <kyle@kkaminsk.com>2012-06-30 14:30:41 -0500
commitd795d12618bc816c547fc6fd50b167c481be9e22 (patch)
tree3c5aa791b5e32acd5431546a04e5fe79cdcc2267 /express
parentf7c4894f42d520126ba957f78d9f888feef32426 (diff)
downloadfubar-d795d12618bc816c547fc6fd50b167c481be9e22.tar.gz
fubar-d795d12618bc816c547fc6fd50b167c481be9e22.tar.bz2
fubar-d795d12618bc816c547fc6fd50b167c481be9e22.zip
add some express samples, and work more
Diffstat (limited to 'express')
-rw-r--r--express/app1.js24
-rw-r--r--express/app2.js55
2 files changed, 79 insertions, 0 deletions
diff --git a/express/app1.js b/express/app1.js
new file mode 100644
index 0000000..8c25531
--- /dev/null
+++ b/express/app1.js
@@ -0,0 +1,24 @@
+var express = require('express');
+
+var app = express.createServer()
+
+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.get('/foo', function(req, res) {
+ res.send('hello, foo!\n');
+})
+app.get('/', function(req, res) {
+ res.send('hello, world!\n');
+})
+app.listen(8081);
+
diff --git a/express/app2.js b/express/app2.js
new file mode 100644
index 0000000..db95537
--- /dev/null
+++ b/express/app2.js
@@ -0,0 +1,55 @@
+var express = require('express');
+var util = require('util');
+
+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(app.router);
+ var oneYear = 31557600000;
+ app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
+
+ app.set('views', __dirname + '/views');
+});
+
+app.get('/*', function(req, res, next) {
+ pagehits++;
+ /* look at app.use*, app.router brings us here since we have a GET match here,
+ * we need to call next() so we pass control to whoever is next
+ */
+ next();
+});
+
+app.get('/info', function(req, res) {
+ res.send('page hits: ' + pagehits + '\n');
+});
+
+app.get('/user/:id([0-9]+)', function(req, res) {
+ res.send('user ' + req.params.id);
+});
+
+app.get('/', function(req, res) {
+ res.send('hello, world!\n');
+});
+
+app.use(function(req, res) {
+ res.writeHead(200, {'Content-Type': 'text/html'});
+ res.write('resorting to connect! could do my original routing\n');
+ res.end();
+});
+
+app.listen(8081);
+