nuxt / http

Universal HTTP Module for Nuxt.js
https://http.nuxtjs.org
MIT License
229 stars 51 forks source link

setHeader and Cors problem. #158

Closed Gu3 closed 3 years ago

Gu3 commented 3 years ago

Hi !

I've got a problem with setHeader function : if I do : $http.setHeader('x-accessid', "20840")

so the response of any request is : Access to fetch at 'https://local.test.fr/api/accesses' from origin 'https://local.admin.test.fr' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

The same request without setHeader function is OK.

Is setHeader Function delete some other header or just add the new one ?

Thank you for your help !

Vincent.

atinux commented 3 years ago

Hi, this is pretty weird it should not change the preflight request. It might be related to ky but I don't see any issue related to it.

Regarding our code, we don't remove any other header when you provide a value: https://github.com/nuxt/http/blob/master/lib/plugin.js#L24

Gu3 commented 3 years ago

Hi ! Thanks for your response :) You're indeed right ! It's a back end issue : my nelmios cors conf doesn't allow this header 🤦‍♂️

allow_headers: ['Content-Type', 'Authorization', 'x-accessid']

Vincent.