A
A
AlexMark2017-08-01 09:04:00
Node.js
AlexMark, 2017-08-01 09:04:00

What is the best way to handle POST requests in Node.js?

Just starting to learn node.js.
I am creating a user login page. When filling out forms, I send his request to pages by type

router.post('/register', 
 userController.validateRegister,
 userController.register,
 authController.login
)
router.post('/login', authController.login);

Question. Is it possible to implement requests to the same page, and how can I check on the server side which request I am working with?
In the middleware, check the values ​​of the hidden input / name of the form, and, in the case of register, go one way, otherwise another?
Or is the option I'm currently using the best way to use POST requests?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
RidgeA, 2017-08-01
@AlexMark


Question. Is it possible to implement requests to the same page, and how can I check on the server side which request I am working with?
Can. But why?
IMHO after registration it is better to return 302 status and redirect to the login page. Or do the same on the frontend if SPA
router.post('/register', 
 userController.validateRegister,
 userController.register,
 authController.login
)

V
Vitaly, 2017-08-01
@vshvydky

a good example on the link quite popularly is an example of api under koa1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question