Created
July 19, 2016 14:55
-
-
Save lennym/4b91c07f2a0fb25dd29bc65408ab8669 to your computer and use it in GitHub Desktop.
Express middleware mounting patterns
This file contains hidden or 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 app = require('express'); | |
app.use(require('./default-middleware')); | |
app.use(require('./router')); | |
module.exports = app; |
This file contains hidden or 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 router = require('express').Router(); | |
const passport = require('passport'); | |
const BasicStrategy = require('passport-http'); | |
passport.use(new BasicStrategy((username, password, done) => { | |
// Some Basic authentication... | |
})); | |
router.use(passport.authenticate('basic')); | |
router.use((err, req, res, next) => { | |
// handle authentication errors | |
}); | |
module.exports = router; |
This file contains hidden or 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 router = require('express').Router(); | |
router.use(require('./body-parser')); | |
router.use(require('./cookie-parser')); | |
module.exports = router; |
This file contains hidden or 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 router = require('express').Router(); | |
router.use('/', require('./routers/home')); | |
router.use('/user', require('./auth'), require('./routers/user')); | |
module.exports = router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment