diff --git a/plugins/srd-gear-router/route.js b/plugins/srd-gear-router/route.js index 5fc7f48..b68d14f 100644 --- a/plugins/srd-gear-router/route.js +++ b/plugins/srd-gear-router/route.js @@ -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 }