redirect is routing POST requests to GET
See original GitHub issueconst Koa = require('koa')
const Router = require('koa-router')
const app = new Koa()
const router = new Router()
router.post('/newRoute/subPath', (ctx) => {
ctx.body = 'Hello, from POST';
});
router.get('/newRoute/subPath', (ctx) => {
ctx.body = 'Hello, from GET';
});
router.put('/newRoute/subPath', (ctx) => {
ctx.body = 'Hello, from PUT';
});
router.delete('/newRoute/subPath', (ctx) => {
ctx.body = 'Hello, from DELETE';
});
router.all(/^\/oldRoute\//, (ctx) => {
const newUrl = ctx.url.replace(/^\/oldRoute\/(.*)/, '/newRoute/$1');
console.log(`-- redirecting request -- ${ctx.url} -> ${newUrl}`);
ctx.redirect(newUrl);
});
app
.use(router.routes())
.use(router.allowedMethods());
app.listen(3002, () => console.log('Koa app listening on 3002'));
Calling localhost:3002/oldRoute/subPath
with GET, PUT, and DELETE methods correctly redirect to the new url with the same method. However, calling that url with a POST method redirects to the new url but ends up in the GET method handler when it should end up in the POST handler for the new url.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6
Top Results From Across the Web
How to redirect to a post route - laravel - Stack Overflow
i want to be redirected to a post route using the redirect instead of a get. My code below public function resolve_booking(Request $request){ ......
Read more >Redirections in HTTP - MDN Web Docs - Mozilla
In HTTP, redirection is triggered by a server sending a special redirect response to a request. Redirect responses have status codes that ...
Read more >Routing - Express.js
For example, the following handler is executed for requests to the route “/secret” whether using GET, POST, PUT, DELETE, or any other HTTP...
Read more >HTTP Redirects - The PHP Framework For Web Artisans
Redirect responses are instances of the Illuminate\Http\RedirectResponse class, ... Since this feature utilizes the session, make sure the route calling the ...
Read more >next.config.js: Redirects
For example, if the browser made a request to POST /v1/users which returned status code 302 with location /v2/users , the subsequent request...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That’s right. The problem was resolved by setting
ctx.status = 308
before redirecting. https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308It seems not to be Koa’s problem. https://stackoverflow.com/questions/8138137/http-post-request-receives-a-302-should-the-redirect-request-be-a-get