post request header not being received on vercel app directory endpoint
Unanswered
American black bear posted this in #help-forum
American black bearOP
Hello,
I have a POST endpoint using the app directory route at url:
The endpoint is queryable, and works fine. However, when trying to obtain an
When logging
route.ts
Its important to note, that my environment variable is what I expect it to be, on both ends. The only problem Im having is that vercel is forwhatever reason stripping my headers.
I have a POST endpoint using the app directory route at url:
/api/worker/[workerId]/pingThe endpoint is queryable, and works fine. However, when trying to obtain an
authorization header it simple doesn't come through on vercels side. It works absolutely fine on my local hosted version, which is the exact same code as whats hosted on vercel. However, when accessing request.headers.get('authorization') vercel just outputs null, even though the request header is being sent. I'm not sure what to do.When logging
request.headers I get a bunch of vercel related headers, such as x-vercel-ip and a bunch more. But my headers which I sent to the endpoint are completely stripped./api/worker/[workerId]/pingroute.ts
import { env } from '@/env';
import { db } from '@/server/db';
import type { NextRequest } from 'next/server';
interface Params {
workerId: string;
}
export async function POST(request: NextRequest, { params }: { params: Params }) {
console.log(1, request.headers.get('authorization'), env.WORKER_AUTH_TOKEN); // null
console.log(2, request.headers.get('authorization'), env.WORKER_AUTH_TOKEN); // null
if (!request.headers.get('authorization') || request.headers.get('authorization') !== env.WORKER_AUTH_TOKEN) {
return new Response(undefined, { status: 401 });
}
return new Response(undefined, { status: 200 });
}Its important to note, that my environment variable is what I expect it to be, on both ends. The only problem Im having is that vercel is forwhatever reason stripping my headers.
5 Replies
American black bearOP
if i use another header name, eg "workerauthtoken" the header appears? 😕
is
authorization a reserved header or somethingIt shouldn’t be, the header is probably stripped by your middleware or something running between the Vercel app and the browser (e.g. a proxy or firewall)
what joulev said, my own experience the
authorization is missing if its a 301 redirect cross origin (ie google.com -> bing.com), but other then that im not sureAmerican black bearOP
okay thanks guys ^:)