Search code examples
gitlabcorsgitlab-cihttp-status-code-302gitlab-pages

(Status: 302) Gitlab Pages JSON translation files CORS policy error & redirect


I have an Angular project in which I use JSON files (path: src/assets/i18n)to translate the content into different languages. I put my project on Gitlab Pages, but I get the following error:

Access to XMLHttpRequest at 'https://gitlab.com/oauth/authorize?client_id=5059a88907e1b093c23df47d996183b101a862a5e53e099b563120d1308db2c1&redirect_uri=https://projects.gitlab.io/auth&response_type=code&state=yjNh6jjcpRaRwWxD1IGehQ==&scope=api' (redirected from 'https://lorenzoname.gitlab.io/assets/i18n/nl.json') from origin 'https://lorenzoname.gitlab.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource

I also get the following error code:

Status Code: 302 => No content available because this request was redirected.

Followed by two requests:

Request URL: https://projects.gitlab.io/auth?domain=https://lorenzoname.gitlab.io&state=MTUxyEVL9u1G1ytX0KbRrQ== Request Method: GET Status Code: 302 Referrer Policy: strict-origin-when-cross-origin

and:

Request URL: https://gitlab.com/oauth/authorize?client_id=5059a88907e1b093c23df47d996183b101a862a5e53e099b563120d1308db2c1&redirect_uri=https://projects.gitlab.io/auth&response_type=code&state=MTUxyEVL9u1G1ytX0KbRrQ==&scope=api Request Method: GET Status Code: 302 Referrer Policy: strict-origin-when-cross-origin

My gitlab-ci.yml job output:

output gitlab-ci

Is there some kind of configuration possible to allow the files to not get blocked or are there some permissions that need to be changed?


Solution

  • I was manage to solve the issue here with the following code inside the app.module.ts file:

    export function HttpLoaderFactory(http: HttpClient) {
      return new TranslateHttpLoader(http, "./assets/i18n/", ".json");
    }
    

    I initially had the same code but without the , "./assets/i18n/", ".json" part.

    For those who have the same problem with JSON translation files inside the /assets/i18n/ folder, don't forget to also edit the angular.json file to:

              "assets": [
                "src/favicon.ico",
                "src/assets",
                {
                  "glob": "*.json",
                  "input": "src/assets/i18n/",
                  "output": "./assets/i18n/"
                }
              ],