Express.js get http method in controller

前端 未结 2 1898
梦谈多话
梦谈多话 2021-02-04 23:35

I am building a registration form (passport-local as authentication, forms as form helper).

Because the registration only knows GET and POST I would like to do the whole

2条回答
  •  逝去的感伤
    2021-02-04 23:52

    The answer was quite easy

    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.

    Finally the node documentation has such detailed information: http://nodejs.org/api/http.html#http_http_request_options_callback

提交回复
热议问题