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 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() }); };
get() function routes the HTTP GET Requests to the path which is being specified with the specified callback functions. Basically it is intended for binding the middleware to your application. Parameters: path: It is the path for which the middleware function is being called.
The express. Router() function is used to create a new router object. This function is used when you want to create a new router object in your program to handle requests.
json() is a built-in middleware function in Express. This method is used to parse the incoming requests with JSON payloads and is based upon the bodyparser. This method returns the middleware that only parses JSON and only looks at the requests where the content-type header matches the type option.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With