Sta*_*tas 0 javascript node.js express ecmascript-6 next.js
我试图弄清楚如何从路由控制器访问应用程序对象。在我的路线文件中我有
const apiController = require('../controllers/mainController')
module.exports = (app) => {
app.post("/stop",
apiController.stopFlow
);
app.post("/specificSearch",
apiController.initiateSearch);
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因,我无法访问(app)这些控制器内部的对象,但是,如果我执行类似的操作
module.exports = (app) =>{
app.post('/stop', (req,res)=>{
console.log(app)
})
}
Run Code Online (Sandbox Code Playgroud)
然后一切正常,所以我很好奇有没有办法将它传递给我的apiController?我的apiController样子是这样的
module.exports = {
async stopFlow(req, res) {
console.log("Stop");
console.log(app)
},
}
Run Code Online (Sandbox Code Playgroud)
我能做什么来解决这个问题?