Next.js Discord

Discord Forum

An unexpected response was received from the server.

Unanswered
Burmese posted this in #help-forum
Open in Discord
BurmeseOP
Sometimes for some users, they get the error eventhough the request was successful.

This is my proxy.ts looks like:

import { cookies } from "next/headers"; import { NextResponse, type NextRequest } from "next/server"; export default async function proxy(request: NextRequest) { const requestHeaders = new Headers(request.headers); const cookieStore = await cookies(); const accessToken = cookieStore.get("access_token"); const onboarding = cookieStore.get("onboarding"); const pathname = request.nextUrl.pathname; if ( !accessToken && (pathname === "/signup/connecting-platforms" || pathname === "/profile/name") ) { return NextResponse.redirect(new URL("/signup", request.url)); } requestHeaders.set("x-pathname", pathname); return NextResponse.next({ request: { headers: requestHeaders, }, }); } export const config = { matcher: [ { source: "/((?!api|_next/static|_next/image|favicon.ico).*)", missing: [ { type: "header", key: "next-router-prefetch" }, { type: "header", key: "next-action" }, { type: "header", key: "purpose", value: "prefetch" }, ], }, ], };

8 Replies

BurmeseOP
Is updating x-pathname cause any issues with some of the server functions?
@Burmese Is updating x-pathname cause any issues with some of the server functions?
I wiuld assume so, internally theres a lot of checking to make sure server action stays secure
BurmeseOP
Do you recommend to not update the header in proxy.ts? @ididntdoshi
BurmeseOP
ok thanks
@Burmese ok thanks
like id think twice in modifying existing header keys but you definetly can still add new header keys and what not to add more context
just clarifying my stance