Last active
July 6, 2017 04:05
-
-
Save jkantr/fc4c0ec5316f88a02f992788c3ab2b25 to your computer and use it in GitHub Desktop.
Mounted Routers as Parametric Modules
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
const express = require('express') | |
const router = express.Router() | |
module.exports = (Knex) => { | |
router.get('/', (req, res) => { | |
// now you have Knex object in scope! | |
res.render('main', { title: 'Main' }) | |
}) | |
return router | |
} |
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
const Knex = "Pretend this is your knex object" | |
const api = require('./routes/api.js')(Knex) | |
app.use('/api', api) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment