Fetch in middleware not accepting custom headers?
Unanswered
GMatrixGames posted this in #help-forum
Hi! First off, yes, I know fetching in middleware isn't necessarily a good thing, but it's for a concept I will flesh out later.
The issue I'm encountering is that I am trying to fetch data from an API endpoint with a custom header "js_sender".
I also inject client cookies into the request, which I'll get to shortly.
Before executing
The problem happens that when I receive the request on my backend, the js_sender cookie is entirely missing, but the cookie header is present:
I cannot replicate it locally, when both NextJS and the backend are running and middleware does the same request. It only seems to happen server-side, and I'm unsure what to do.
Any help would be greatly appreciated!
The issue I'm encountering is that I am trying to fetch data from an API endpoint with a custom header "js_sender".
I also inject client cookies into the request, which I'll get to shortly.
Before executing
fetch
, I have logged the value of the init
variable for fetch and this is what it contains:{
headers: {
js_sender: 'JumpStart Middleware',
Cookie: '<client cookies>'
}
}
The problem happens that when I receive the request on my backend, the js_sender cookie is entirely missing, but the cookie header is present:
Headers {
Host: 'REDACTED',
'X-Forwarded-Scheme': 'https',
'X-Forwarded-Proto': 'https',
'X-Forwarded-For': 'REDACTED',
'X-Real-IP': 'REDACTED',
Connection: 'close',
'cdn-loop': 'cloudflare; loops=1',
accept: '*/*',
'accept-encoding': 'gzip, br',
'cf-ipcountry': 'US',
'x-middleware-subrequest': 'src/middleware',
'user-agent': 'Next.js Middleware',
'cf-visitor': '{"scheme":"https"}',
'cf-connecting-ip': 'REDACTED',
'sec-fetch-mode': 'cors',
'accept-language': '*',
cookie: '<client cookies>'
}
I cannot replicate it locally, when both NextJS and the backend are running and middleware does the same request. It only seems to happen server-side, and I'm unsure what to do.
Any help would be greatly appreciated!