Skip to main content
Question

GET request with the "Accept-Language" header being blocked


Mateus_Pinheiro

I have the following code:

1async function fetchNamespace(locale: string, namespace: string): Promise<Object> {
2 const url = `https://myapiurl.com/v1/translation/${namespace}?format=flat`
3 const headers = { "Accept-Language": locale }
4 const response = await fetch(url, { method: 'GET', headers: headers })
5
6 const content = await response.json() as any
7 return content[Object.keys(content)[0]]
8}

 

It gives me the following error:

Access to fetch at 'https://myapiurl.com/v1/translation/nes?format=flat' from origin 'null' has been blocked by CORS policy: Request header field accept-language is not allowed by Access-Control-Allow-Headers in preflight response

 

Is there a way to allow the "Accept-Language" header somewhere? I know the header is the problem because:

  • I've tried sending the same request without the headers and it works
  • I've sent the same request over CURL with Origin set to null, and it also works.

The CURL command that's working:

1curl -X GET "https://myapi.com/v1/translation/nes?format=flat" \
2-H "Accept-Language: en_US" \
3-H "Origin: null"

 

Any ideas?

This topic has been closed for replies.

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings