1// GET 'http://www.example.com/admin/new?a=b'
2app.get('/admin', (req, res, next) => {
3 req.originalUrl; // '/admin/new?a=b' (full path with query string)
4 req.baseUrl; // '/admin'
5 req.path; // '/new'
6 req.baseUrl + req.path; // '/admin/new' (full path without query string)
7});
1res.redirect('/foo/bar')
2res.redirect('http://example.com')
3res.redirect(301, 'http://example.com')
4res.redirect('../login')
5
1// send the rendered view to the client
2res.render('index')
3
4// if a callback is specified, the rendered HTML string has to be sent explicitly
5res.render('index', function (err, html) {
6 res.send(html)
7})
8
9// pass a local variable to the view
10res.render('user', { name: 'Tobi' }, function (err, html) {
11 // ...
12})
13