-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code to separate index page and results page rendering
- Loading branch information
1 parent
ffc1deb
commit 3cf81af
Showing
3 changed files
with
33 additions
and
16 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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const validateSessionResult = (req, res, next) => { | ||
if (!req.session.result) { | ||
return res.redirect('/'); | ||
} | ||
next(); | ||
} | ||
|
||
module.exports = { | ||
validateSessionResult | ||
}; |
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,24 +1,12 @@ | ||
const { Router } = require('express'); | ||
const router = Router(); | ||
const { calculate } = require('../controllers/index'); | ||
const { indexPage, resultsPage, calculate } = require('../controllers/index'); | ||
const { validateSessionResult } = require('../middlewares/index'); | ||
|
||
router.get('/', (req, res) => { | ||
res.render('index', { | ||
title: 'Calculadora VLSM', | ||
page: 'index' | ||
}); | ||
}); | ||
router.get('/', indexPage); | ||
|
||
router.post('/calculate', calculate); | ||
|
||
router.get('/results', (req, res) => { | ||
let data = req.session.result; | ||
|
||
res.render('results', { | ||
title: 'Calculadora VLSM | Resultados', | ||
page: 'results', | ||
data | ||
}); | ||
}); | ||
router.get('/results', validateSessionResult, resultsPage); | ||
|
||
module.exports = router; |