Closed TimGuendel closed 9 months ago
That code example is too vague for me to find where the issue is.
I narrowed it down to this line. Here is the whole thing:
proxy: {
proxies: {
'/api': {
target: process.env.BACKEND_URL,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
xfwd: true,
configure: (proxy) => {
proxy.on('proxyReq', (proxyReq) => {
function getCookieFromString(cookiesString: string, cookieName: string): string | null {
return (cookiesString ?? '').match(`(^|;)\\s*${cookieName}\\s*=\\s*([^;]+)`)?.pop() ?? null;
}
const cookie = proxyReq.getHeader('cookie') as string;
const token = getCookieFromString(cookie, 'token');
const ALLOWED_HEADERS = ['host', 'x-forwarded-for', 'x-real-ip'];
proxyReq.getHeaderNames().forEach((headerName) => {
if (!ALLOWED_HEADERS.includes(headerName)) {
proxyReq.removeHeader(headerName); // This line here causes the error with Node 20+
}
});
if (token) {
proxyReq.setHeader('token', token);
}
});
},
},
},
},
can you try to change the ALLOWED_HEADERS
to:
const ALLOWED_HEADERS = ['Host', 'X-Forwarded-For', 'X-Real-Ip'];
and tell me if that works for you, if not then it might be another issue on my end. Other than that what error exactly pops up?
can you try to change the
ALLOWED_HEADERS
to:
const ALLOWED_HEADERS = ['Host', 'X-Forwarded-For', 'X-Real-Ip'];
and tell me if that works for you, if not then it might be another issue on my end. Other than that what error exactly pops up?
This causes an error 400 right away 👀 (with node 18 AND node 20)
[nuxt] [request error] [fatal] [400] Error fetching data: AxiosError: Request failed with status code 400
I've pushed an update for the proxy package this module uses. update the module.
The error still occurs with the new version (with both Node Versions)
[nuxt] [request error] [fatal] [400] Error fetching data: AxiosError: Request failed with status code 400
are you using the captialized headers?
are you using the captialized headers?
Yes. As soon as I do, I get an error 400
try the non-capitalized ones too?
I did, see here:
The error still occurs with the new version (with both Node Versions)
[nuxt] [request error] [fatal] [400] Error fetching data: AxiosError: Request failed with status code 400
Can you check in whatever lockfile you're utilizing what version @refactorjs/http-proxy
is?
I have 2 entries with "@refactorjs/http-proxy":
"@nuxt-alt/proxy@npm:^2.4.9":
version: 2.4.9
resolution: "@nuxt-alt/proxy@npm:2.4.9"
dependencies:
"@nuxt/kit": ^3.8.1
"@refactorjs/http-proxy": latest
defu: ^6.1.3
picocolors: ^1.0.0
checksum: f48536b22b4e904ad26362caaec02b2170c4e890f0cbc1871323f4596ed6a96df7d1fbdba3492d72b362318759acd0b37c184785ceec679242ad2e32fb676ab4
languageName: node
linkType: hard
"@refactorjs/http-proxy@npm:latest":
version: 0.2.5
resolution: "@refactorjs/http-proxy@npm:0.2.5"
dependencies:
requires-port: ^1.0.0
checksum: 7e9a81cdb08ff9f2597714d30346f342b052602f323992596a42eee6d6e0c06d45b32aa5f751a2ab70b00fbdffe75276e74de00e45c3469c0cef3ad6d0303b34
languageName: node
linkType: hard
I don't know what else to tell you. I'm unable to replicate the issue you're facing. I assumed it's a 'Headers already sent issue' but even that I am unable to replicate.
Ok. I'll keep you updated if I find anything new.
Quick update: I switched to a proxy inside a server eventHandler and I am having the same problem when using Node 20. So your library is not at fault.
In my proxy, this used to work with Node 18.18.2:
When using Node 20.10.0 (LTS), the call times out ⚠️. If I comment out this line:
proxyReq.removeHeader(headerName);
it works again 👀