jlengstorf
jlengstorf2y ago

fetch not following redirects

quick question about the HTTP Actions: I'm getting some inconsistencies in how the Fetch API works, and I'm not sure if they're expected I have a shortlink, and if I fetch it, I would expect it to follow that redirect and then set req.url to the target URL. in Node, this happens how I expect. in Convex, I'm still getting the shortlink in req.url
const res = await fetch('https://example.com/shortlink');
const headers = res.headers;

console.log(res.url);
const res = await fetch('https://example.com/shortlink');
const headers = res.headers;

console.log(res.url);
is this intended behavior?
8 Replies
ballingt
ballingt2y ago
This is a known shortcoming, the Convex runtime doesn't implement redirects or some of the options of the fetch API yet. This is on the list, we'll let you know when it's in.
jlengstorf
jlengstorfOP2y ago
gotcha. thanks!
punn
punn2y ago
second this ^ we'd really like to redirect from http convex endpoints
ballingt
ballingt2y ago
You can redirect from Convex http endpoints today, syntax looks like
return Response.redirect("http://place-to-redirect/to");
return Response.redirect("http://place-to-redirect/to");
the request in this thread is about fetch() calls initiated in V8 actions not following redirects
punn
punn2y ago
I see, thank you
lee
lee2y ago
@jlengstorf by the way, the Convex runtime already follows redirects in fetch (and always has). but it doesn't set Response.url or Response.redirected correctly. I'm working on those now and it should be working today or tomorrow
jlengstorf
jlengstorfOP2y ago
thanks Lee! I knew it was following, which was great, but for my weird use case the specific thing I needed was the Response.url
lee
lee2y ago
this should be working now. let us know if you run into any more problems

Did you find this page helpful?