Adjust router to be cleaner
parent
fbc077a0f1
commit
53bd1ffeed
|
@ -4,35 +4,28 @@ const path = require('path')
|
|||
|
||||
module.exports = (plugin, app) => {
|
||||
// gear, gear/type, gear/type/name
|
||||
router.get('/gear', async function(req, res) {
|
||||
router.get(['/gear', '/gear/:type', '/gear/:type/:name'], async function(req, res) {
|
||||
let entry = null
|
||||
if (req.params.name) {
|
||||
if (!app.live.db.gear[req.params.type]) {
|
||||
// TODO: 404 - no such gear type
|
||||
} else {
|
||||
entry = app.live.db.gear[req.params.type].find(v=>v.name===req.params.name)
|
||||
if (!entry) {
|
||||
// TODO: 404 - no such gear by name
|
||||
}
|
||||
}
|
||||
}
|
||||
res.render('index', {
|
||||
content: app.dot.tables({...req.params, db: app.live.db.gear}),
|
||||
content: app.dot.tables({...req.params, db: app.live.db.gear, entry: entry}),
|
||||
menu: app.live.menu,
|
||||
title: 'gear',
|
||||
www_name: app.live.conf.www_name,
|
||||
www_copyright: app.live.conf.www_copyright,
|
||||
})
|
||||
})
|
||||
router.get('/gear/:type', async function(req, res) {
|
||||
res.render('index', {
|
||||
content: app.dot.tables({...req.params, db: app.live.db.gear}),
|
||||
menu: app.live.menu,
|
||||
title: 'gear',
|
||||
www_name: app.live.conf.www_name,
|
||||
www_copyright: app.live.conf.www_copyright,
|
||||
})
|
||||
})
|
||||
router.get('/gear/:type/:name', async function(req, res) {
|
||||
res.render('index', {
|
||||
content: app.dot.tables({...req.params, db: app.live.db.gear}),
|
||||
menu: app.live.menu,
|
||||
title: 'gear',
|
||||
www_name: app.live.conf.www_name,
|
||||
www_copyright: app.live.conf.www_copyright,
|
||||
})
|
||||
})
|
||||
|
||||
return router
|
||||
|
||||
plugin.log('added gear route')
|
||||
|
||||
return router
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue