1
我是Express.js的新手,但我想以正確的方式學習它。因此,我已經開始使用Peter Lyon建議的代碼結構:https://github.com/focusaurus/express_code_structure。我下面一個passport.js教程,需要我的護照對象傳遞給我的路由器,我卡在那裏將對象傳遞給路由器
這是我的index.js:
appCommon.head(app, passport)
// Load all Routers
app.use('/', require('./pages/router'))
app.use('/projects', require('./projects/router'))
app.use('/', require('./authentication/router'))(passport) // Pass passport to router
我的認證/路由器。 JS:
var express = require('express')
var join = require('path').join
var router = new express.Router()
// I removed the other functions
function processSignup (req, res) {
passport.authenticate('local-signup', {
successRedirect : '/profile', // redirect to the secure profile section
failureRedirect : '/signup', // redirect back to the signup page if there is an error
failureFlash : true // allow flash messages
})
}
router.use(express.static(join(__dirname, '../../wwwroot')))
router.get('/login', login)
router.get('/signup', signup)
router.post('/signup', processSignup)
router.get('/profile', isLoggedIn, profile)
router.get('/logout', logout)
module.exports = router
問題:
- 我是否正確地將護照對象傳遞給我的路由器?
- 如何將護照對象添加到我的路由器以便processSignup函數知道它?