Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

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

Open
gcherem opened this issue Feb 8, 2021 · 5 comments
Open

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

gcherem opened this issue Feb 8, 2021 · 5 comments

Comments

@gcherem
Copy link

gcherem commented Feb 8, 2021

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
Copy link

franj0 commented Mar 25, 2021

+1

@duffbeeeer
Copy link

Having the same issue.

@spdi
Copy link

spdi commented Jun 16, 2021

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
Copy link

duffbeeeer commented Jun 16, 2021

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: ngx-translate/core#921. will report back.

@duffbeeeer
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants