nuxt / nuxt

The Intuitive Vue Framework.
https://nuxt.com
MIT License
54.63k stars 5k forks source link

Can't replace headers in `useFetch` with `baseURL` on SSR #23827

Closed ExEr7um closed 11 months ago

ExEr7um commented 1 year ago

Environment

Reproduction

Tried to make it, but I think StackBlitz doesn't proxy browser headers on request.

Describe the bug

I'm using Accept-Language header to get localized data from API. There is strange behavior on SSR when using baseURL.

With baseURL

I make a request like this:

const test = await useFetch("/", {
  baseURL: "https://someurl",
  headers: {
    "Accept-Language": "test",
  },
})

On server side it proxies headers from browser and merges them with my provided header, so what I get is:

Accept-Language: ["ru", "test"]

But on client side it replaces browser headers with mine, so I get:

Accept-Language: "test"

Without baseURL

I make the same request without using baseURL:

const test = await useFetch("https://someurl", {
  headers: {
    "Accept-Language": "test",
  },
})

That way, there is no error, both on client and on server side it replaces browser headers with mine. So the issue only happens when using baseURL. So I get:

Accept-Language: "test"

Additional context

No response

Logs

No response

aaharu commented 12 months ago

Similarly, there is a bug that if you set baseURL in useFetch, you cannot change the request header using Headers.

https://stackblitz.com/edit/github-ylrkxf?file=app.vue

danielroe commented 12 months ago

cc: @pi0

darioferderber commented 11 months ago

@ExEr7um have you tried with v3.8.1?

danielroe commented 11 months ago

Yes, this was resolved in https://github.com/nuxt/nuxt/pull/23884. Thank you for investigating @darioferderber ❤️

ExEr7um commented 11 months ago

Yes, now it works correctly. Thanks!