Next.js Discord

Discord Forum

Next 14 - Middleware Rewrite returns 308 to the client

Unanswered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
As the title says i using the MW as some kind of proxy and it worked well before 14. Now with the update middleware rewrite returns a 308 to the browser which then tries to do the requests and fails obviously.

As you can see in the Screenshot the internal headers are all present. Anyone have a idea what im doing wrong?

Thats my proxy code

const proxy = async (request: NextRequest, destination: string) => {
  const requestHeaders = new Headers(request.headers);

  const transactionToken = request.cookies.get("transactionToken")?.value;

  if (transactionToken) requestHeaders.set("Authorization", transactionToken);

  console.log("rewrite path", `${process.env.API_BASE_URL}${destination}`);

  return NextResponse.rewrite(`${process.env.API_BASE_URL}${destination}`, {
    request: {
      headers: requestHeaders,
    },
  });
};

0 Replies