forked from DamonOehlman/connectables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.js
44 lines (35 loc) · 1.32 KB
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var connect = require('connect'),
connectables = require('../');
function sayHello(req, res, next) {
res.end('hello: ' + req.params.param);
} // sayHello
var server = connect.createServer(
connect.logger(),
connectables.router(function(router) {
router.get('/', function(req, res, next) {
res.end('Hi');
});
router.get('/docs/:category?', function(req, res, next) {
if (! req.params.category) {
res.end('No category specified, guess I should list all the docs');
}
else {
res.end('You asked for the doc category: ' + req.params.category);
}
});
router.get('/doc/:id', function(req, res, next) {
res.end('You asked for doc id: ' + req.params.id);
});
router.get('/the/*/*/on/the/*', function(req, res, next) {
var splat = req.params['*'],
phrase = 'the ' + (splat[0] || '') + ' ' +
(splat[1] || '') + ' ' +
'on the ' + (splat[2] || '');
res.end(phrase);
});
router.get('/test/subpath?', sayHello);
router.get('', sayHello);
router.get('/paramtest/:param?', sayHello);
})
);
server.listen(3000);