http-loader icon indicating copy to clipboard operation
http-loader copied to clipboard

How to get translations files from other server (fix cors error)

Open gcherem opened this issue 4 years ago • 5 comments

When getting translations from other server like this


export function HttpLoaderFactory(http: HttpClient) {
  return new TranslateHttpLoader(http, 'http://www.example.com/assets/i18n/', '/translations.json');
}

I get the following cors error:

Access to XMLHttpRequest at 'http://www.example.com/assets/i18n/en_US/translations.json' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Can anyone help with that? Thanks in advance.

gcherem avatar Feb 08 '21 23:02 gcherem

+1

franj0 avatar Mar 25 '21 08:03 franj0

Having the same issue.

duffbeeeer avatar Jun 16 '21 07:06 duffbeeeer

It's not the problem of ngx-translate. Read: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

In short, remote server which holds translations should add header in response: Access-Control-Allow-Origin: *

spdi avatar Jun 16 '21 10:06 spdi

Well the remote server is the angular web server. I have already enabled crossOrigin flag in angular builder and updated nginx config. Still cors issue with retrieving json from resource. Im suspecting this is linked to the Interceptor issue. I have several Angular FEs running and none of them have the issue except for the one with Interceptor enabled.

Im trying this now: https://github.com/ngx-translate/core/issues/921. will report back.

duffbeeeer avatar Jun 16 '21 11:06 duffbeeeer

circumventing the HttpIntecptor fixed the issue for me. no more cors errors.

duffbeeeer avatar Jun 16 '21 13:06 duffbeeeer