Skip to content

Commit f93b23e

Browse files
author
codingChewie
committed
Challenges: Redirects
1 parent 0d3c74e commit f93b23e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

app.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ app.set('view engine', 'pug')
1212
app.get('/', (req, res) => {
1313
const name = req.cookies.username
1414

15-
res.render('index', { name })
15+
if (name) return res.render('index', { name })
16+
17+
res.redirect('/hello')
1618
})
1719

1820
app.get('/cards', (req, res) => {
@@ -24,9 +26,11 @@ app.get('/cards', (req, res) => {
2426
})
2527

2628
app.get('/hello', (req, res) => {
27-
res.render('hello', {
28-
name: req.cookies.username,
29-
})
29+
const name = req.cookies.username
30+
31+
if (name) return res.redirect('/')
32+
33+
res.render('hello')
3034
})
3135

3236
app.post('/hello', (req, res) => {

0 commit comments

Comments
 (0)