Express.js get http method in controller

前端 未结 2 1900
梦谈多话
梦谈多话 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-05 00:01

    Now you can use a package in npm => "method-override", which provides a middle-ware layer that overrides the "req.method" property.

    Basically your client can send a POST request with a modified "req.method", something like /registration/passportID?_method=PUT.

    The

    ?_method=XXXXX

    portion is for the middle-ware to identify that this is an undercover PUT request.

    The flow is that the client sends a POST req with data to your server side, and the middle-ware translates the req and run the corresponding "app.put..." route.

    I think this is a way of compromise. For more info: method-override

提交回复
热议问题