Request losts when POSTing redirected url
jonathanffon opened this issue · comments
galago commented
I hosted a web on port 3000 and served my API on port 3080. All POSTs of "/api/" were redirected to "localhost:3080/". In serve.json
, I have:
"redirects": [
{
"source": "/api/:obj",
"destination": "http://localhost\\:3080/:obj"
}
]
It was OK for GET method, but for POST method, req.body
was empty when it was redirected to port 3080.
Here is POST results issued by curl
. The difference was caused by request lose:
➜ curl -L -H 'Content-Type:application/json' -X POST http://localhost:3000/api/timers -d '{"title":"test1"}'
{
"id": 12
}%
➜ curl -L -H 'Content-Type:application/json' -X POST http://localhost:3080/timers -d '{"title":"test2"}'
{
"title": "test2",
"id": 13
}%
Any fix to this problem ?
Warren Bank commented
try this:
{
"redirects": [
{
"source": "/api/:obj",
"destination": "http://localhost\\:3080/:obj",
"type": 307
}
]
}
references:
- similar discussion on SO regarding how to do this with Apache
- tl;dr: send status code
307
rather than301
- tl;dr: send status code
galago commented
try this:
{ "redirects": [ { "source": "/api/:obj", "destination": "http://localhost\\:3080/:obj", "type": 307 } ] }references:
similar discussion on SO regarding how to do this with Apache
- tl;dr: send status code
307
rather than301
Thank you @warren-bank . That's great. I have tried 307 and 308. Both work for me.