export default () => new Response.redirect("https://example.com", 302)
This doesn’t work. Instead I am having to setup the headers and status of the returned response to make a redirect, which I’m guessing I shouldn’t need to do:
Looking at the Web API documentation for Edge Functions, redirect is not supported (currently at least), so you need to use the Location header method.
First of all, I wanted to thank everyone who chimed in on this thread and helped find a workaround for the cookies + Response.redirect limitation. Your contributions are much appreciated!
Improving the Edge Functions experience is something we’ve been actively working on, and so I wanted to share an update on this specific use case.
It is now possible to set cookies (either by using the context.cookies.set utility method or by setting the set-cookie header manually) and return a redirect constructed with Response.redirect.
Additionally, Response.redirect now accepts a relative path, which means you can use it without having to provide the full URL.
Example:
import type { Context } from "https://edge.netlify.com";
export default async (req: Request, context: Context) => {
context.cookies.set({
name: "my-cookie-1",
value: "chocolate-chip",
expires: new Date("2028-12-31"),
});
return Response.redirect("/new-path");
};
This is available with version 13.1.0 of the Netlify CLI.
If you’re still experiencing any issues, please us know on this thread.