1
您好我是新手來表達js我想在路線中放置多個功能,請解釋一下如何在路線中添加多個功能,我在company.js中有2個功能,知道如何導出,並在index.js它添加快遞js內路線多功能
index.js
var router = require('express').Router();
var path = require('path');
// Rest API
require(path.join(__dirname, './', 'company'))(router);
// Homepage/Client
router.get('/', function(req, res, next) {
res.sendFile(path.join(__dirname, '../', 'client', 'index.html'));
});
module.exports = function(app, passport) {
// set authentication routes
require('./authentication.js')(app, passport);
// set other routes
app.use('/', router);
};
company.js
var sockets = require('../utilities/socket');
var authenticationMiddleware =
require('../middlewares/authentication.js');
var companyModel = require('../models/company.js');
var getCompanyProfile = function(router){
router.post('/api/v1/profile/fetchCompany', authenticationMiddleware.isLoggedIn,
function(req, res) {
companyModel.getCompanyProfile(req['user'].id_user,
function(result){
return res.json(result);
});
}
);
},
var saveCompanyProfile = function(router){
router.post('/api/v1/profile/saveCompany', authenticationMiddleware.isLoggedIn,
function(req, res) {
companyModel.saveCompanyProfile(req,
function(result){
return res.json(result);
});
}
);
}
module.exports = getCompanyProfile;
引發錯誤等 router.post( '/ API/V1 /簡檔/ getCompanyProfile',authenticationMiddleware.isLoggedIn, ^ TypeError:無法讀取未定義的屬性「post」 – veeran
您需要將路由器參數傳遞給像'company.getCompanyProfile(router);' –
這些函數是的,我做了它,並在答案 – veeran