如何在sails.js 中对API 请求调用自定义控制器? [英] How to call custom controllers on API reques in sails.js?
本文介绍了如何在sails.js 中对API 请求调用自定义控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的目录结构是这样的:
I have my directory structure like this:
-api
-controllers
-profile
-create.js
在 create.js 中
inside create.js
exports.createUser = async (req, res) => {
... some code ....
}
我是这样调用路由的
-config
-routes.js
在routes.js
module.exports.routes = {
// create new user
'POST /api/v1/user/create': {action: 'profile/create'}
};
我想针对上述请求调用 createUser
函数,但它对我不起作用,该函数未被调用,请帮忙.
I want to invoke createUser
function on this above request, but it is not working for me, the function is not being called, Please help.
推荐答案
您应该通过将控制器功能分配给 module.exports
而不是 module.exports.createUser
来导出控制器功能>.
You should export the controller function by assigning it to module.exports
not to module.exports.createUser
.
你可以试试下面的方法吗?
Could you try it as below?
module.exports = async (req, res) => {
... some code ....
}
这篇关于如何在sails.js 中对API 请求调用自定义控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文