I have the following code:
async function fetchNamespace(locale: string, namespace: string): Promise<Object> {
const url = `https://myapiurl.com/v1/translation/${namespace}?format=flat`
const headers = { "Accept-Language": locale }
const response = await fetch(url, { method: 'GET', headers: headers })
const content = await response.json() as any
return content[Object.keys(content)[0]]
}
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:
curl -X GET "https://myapi.com/v1/translation/nes?format=flat" \
-H "Accept-Language: en_US" \
-H "Origin: null"
Any ideas?