This repository has been archived by the owner on Dec 23, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Craig Condon
committed
Jan 23, 2012
1 parent
6a76863
commit 06ef7c8
Showing
3 changed files
with
123 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,50 @@ | ||
|
||
|
||
## Basic Example | ||
|
||
```javascript | ||
var express = require('express'), | ||
app = express.createServer(), | ||
connectRouter = require('connect-router'); | ||
|
||
var connectRouter = require('connect-router'), | ||
express = require('express'), | ||
app = express.createServer(); | ||
app.use(connectRouter.create(function(router) { | ||
|
||
|
||
//you can use existing middleware to explictly define | ||
//them in routes | ||
router.on('parseBody', express.bodyParser()); | ||
|
||
/** | ||
*/ | ||
|
||
var appRouter = connectRouter.createRouter(app); | ||
router.on('-method=POST user/exists', function(req, res, next) { | ||
|
||
if(userExists(req.query.username)) { | ||
|
||
res.send('That username already exists'); | ||
return; | ||
|
||
} | ||
|
||
appRouter.on('get validateUser -> myProfile', function(req, res, next) { | ||
|
||
}); | ||
next(); | ||
}); | ||
|
||
/** | ||
* signs the user up | ||
*/ | ||
|
||
appRouter.on('get validateUser -> my/profile', function(req, res, next) { | ||
|
||
}); | ||
router.on('-method=POST parseBody -> user/exists -> signup', function(req, res, next) { | ||
|
||
res.send('Successfuly signed up '); | ||
|
||
}); | ||
|
||
})); | ||
|
||
|
||
|
||
|
||
app.listen(8080); | ||
``` | ||
|
||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,42 @@ | ||
var express = require('express'), | ||
app = express.createServer(), | ||
connectRouter = require('../'), | ||
appRouter = connectRouter.create(app); | ||
connectRouter = require('../'); | ||
|
||
|
||
|
||
appRouter.on('get hello/world', function(req, res) { | ||
|
||
console.log(req); | ||
|
||
}); | ||
|
||
|
||
app.use(connectRouter.create(function(router) { | ||
|
||
router.on('parseBody', express.bodyParser()); | ||
router.on('parseCookies', express.cookieParser()); | ||
|
||
|
||
router.on('-method=GET parseCookies -> authorize', function(req, res, next) { | ||
|
||
console.log('Authorize'); | ||
|
||
next(); | ||
}); | ||
|
||
router.on('/**', function(req, res, next) { | ||
|
||
console.log('some greedy middleware'); | ||
|
||
next(); | ||
|
||
}); | ||
|
||
|
||
router.on('-method=GET authorize -> hello/:name', function(req, res, next) { | ||
|
||
console.log("DONE"); | ||
res.send(req.params.name); | ||
}); | ||
|
||
})); | ||
|
||
|
||
|
||
|
||
app.listen(8080); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters