如果这听起来令人困惑,或者之前已经得到解答,请提前抱歉。
使用node.js,express和express-generator,我创建了一个包含两个路径文件的应用程序:
两个路由都需要快速功能,但如果我在两个路由文件中都需要表达它会给我一个错误。有没有办法允许两个路由文件使用相同的快速路由器?
app.js
var express = require('express');
// Other generated requires
var data = require('./routes/data');
var auth = require('./routes/auth');
var app = express();
// Other generated sets and uses
app.use('/', data);
// "login" and "admin" need to use both data.js and auth.js <----------------
//app.use('/login', data);
//app.use('/login', auth);
//app.use('/admin', data);
//app.use('/admin', auth);
module.exports = app;
路由/ data.js
var express = require('express');
var router = express.Router();
// Database functions
router.get('/', function (request, response) {
response.render('index');
});
module.exports = router;
路由/ auth.js
var express = require('express');
var session = require('express-session');
var directory = require('activedirectory');
var router = express.Router();
// Login and session functions
router.get('/login', function (request, response) {
// Login and session check
response.render('login');
});
router.get('/admin', function (request, response, next) {
// Session check
response.render('admin');
});
module.exports = router;