本文介绍了Express.js在控制器中获取http方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在构建一个注册表单(本地护照作为身份验证,表单作为表单助手).
I am building a registration form (passport-local as authentication, forms as form helper).
因为注册只知道GET和POST,所以我想在一个函数中进行整个处理.
Because the registration only knows GET and POST I would like to do the whole handling in one function.
换句话说,我正在寻找类似的东西:
With other words I am searching after something like:
exports.register = function(req, res){
if (req.isPost) {
// do form handling
}
res.render('user/registration.html.swig', { form: form.toHTML() });
};
推荐答案
答案很简单
exports.register = function(req, res) {
if (req.method == "POST") {
// do form handling
}
res.render('user/registration.html.swig', { form: form.toHTML() });
};
但是我在快速指南中搜索了很长时间.
But I searched a long time for this approach in the express guide.
最后,节点文档具有以下详细信息: http://nodejs.org/api/http.html#http_http_request_options_callback
Finally the node documentation has such detailed information:http://nodejs.org/api/http.html#http_http_request_options_callback
这篇关于Express.js在控制器中获取http方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!