node.js - Redirect POST request to PUT in express -
background: i've written rest api express, extends , modifies old api wrote in python. old api wasn't restful: "modify/insert/delete" requests done via post
, , query structure different new api.
in short, want write middleware on new api redirect requests in form of old api, handled routes of new api. middleware needs self-contained, i.e. don't want individual routes handle redirection logic.
this requires redirecting requests, obviously. know can redirect
method, in (slight pseudocode):
app.use('/', (req, res, next) => { if (requestisold(req)) { return res.redirect(newroute(req)); } return next(); });
and know can ask client make new request the same method, with:
res.redirect(307, newroute);
however, leads post
requests modify/delete data going post
requests on new api, handled "add" request handlers.
how redirect post requests , request method changed e.g. put or delete?
Comments
Post a Comment