You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to set some headers based on the user request i first received on the server side.
Common use case to attach the requesting IP address to x-forwarded-for header to enable correct IP locale detection server side. I also attempted using useGqlHost to add query parameters but they also seem immutable after the first change.
The code snippet I use to update the headers on each request:
plugins/gql-addheaders.ts
export default defineNuxtPlugin({
async setup(nuxtApp) {
const router = useRouter();
const headers = {
'x-no-cache': router.currentRoute.value.query?.test ? 'true' : 'false',
'x-forwarded-for': '',
};
if (nuxtApp.ssrContext) {
const ipaddress = nuxtApp.ssrContext?.event.node.req.headers['x-forwarded-for'] as string || '';
headers['x-forwarded-for'] = ipaddress.split(',')[0];
}
console.log(headers);
// Headers are only set on first request
useGqlHeaders(headers);
// Params are only set on first request
useGqlHost(`?x-no-cache=${headers['x-no-cache']}&x-forwarded-for=${headers['x-forwarded-for']}`);
},
});
Expected behaviour
The headers should be updated on each request. The server side logs show that the headers remain the same even after subsequent requests to useGqlHeaders
Reproduction
No response
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered:
Environment
Describe the bug
I need to set some headers based on the user request i first received on the server side.
Common use case to attach the requesting IP address to
x-forwarded-for
header to enable correct IP locale detection server side. I also attempted usinguseGqlHost
to add query parameters but they also seem immutable after the first change.The code snippet I use to update the headers on each request:
plugins/gql-addheaders.ts
Expected behaviour
The headers should be updated on each request. The server side logs show that the headers remain the same even after subsequent requests to
useGqlHeaders
Reproduction
No response
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: