ngx-translate / http-loader

A loader for ngx-translate that loads translations with http calls
MIT License
191 stars 69 forks source link

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

Open gcherem opened 3 years ago

gcherem commented 3 years ago

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.

franj0 commented 3 years ago

+1

duffbeeeer commented 3 years ago

Having the same issue.

spdi commented 3 years ago

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: *

duffbeeeer commented 3 years ago

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 commented 3 years ago

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