Here is my exercise code but look like this code is duplicated.
I want refactoring this code.
can you show me example to solve problem please??
var request = require('request')
request('http://dev-exam.com/api/dashboard', function (error, response, body) {
app.get('/', (req, res) => {
sess = req.session
res.render('index.html', { title: 'Index', data: JSON.parse(body)})
})
app.get('/all', (req, res) => {
sess = req.session
res.render('all.html', {title: 'All', data: JSON.parse(body), id: 0})
})
app.get('/all/:id', (req, res) => {
sess = req.session
res.render('all.html', {title: 'All', data: JSON.parse(body), id: req.params.id})
})
app.get('/settings', (req, res) => {
if(sess.login) {
res.render('settings.html', { title: ' Settings', data: JSON.parse(body) })
} else {
res.redirect('/')
}
})
via Tanz Smiley
No comments:
Post a Comment