Last active
January 4, 2019 12:37
-
-
Save evanxg852000/bfd58fcae64c5493dc25069eb5729260 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
app.route((router) => { | |
router.get('/template', (req, res) => { | |
let data = {title: 'Home', test:true, items: ['Evan', 'John', 'Jane']} | |
res.render('index.html', data) | |
}) | |
// routing with optional parameter | |
router.get('/hello/:name?', (req, res) => { | |
let name = req.params['name'] || 'world' | |
res.end(`Hello ${name}!`) | |
}) | |
// route prefixing with group | |
router.group('/settings', (router) => { | |
router.get('/basic', (req, res) => { | |
res.end('Basic Settings') | |
}) | |
router.get('/notification', (req, res) => { | |
res.end('Notification Settings') | |
}) | |
}) | |
// example of midleware handler chaining | |
router.get('/chain/example', [ | |
(req, res, next) => { | |
req.chain = 'one ->' | |
next() | |
}, | |
(req, res, next) => { | |
req.chain = `${ req.chain} two ->` | |
next() | |
}, | |
(req, res) => { | |
res.end(`${req.chain} three`) | |
} | |
] | |
) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment