Cors w Angularze - Jak obejść

0
  public getAssets(): Observable<IAsset[]> {
    return this.http.get<IAsset[]>('https://www.cryptingup.com/api/assets', {
      headers: {
        'Content-Type': 'application/json',
        'Access-Control-Allow-Origin': '*',
      }
    })
  }

Jakieś pomysły?
W zrzucie log errorów

1

A widzisz tam w nagłówkach, żeby gdzieś pozwalali na CORSy? Musisz sobie postawić jakiś backend, który będzie robił za proxy.

1
One of the allowed methods:
    GET
    HEAD
    POST
Apart from the headers automatically set by the user agent (for example, Connection, User-Agent, or the other headers defined in the Fetch spec as a forbidden header name), the only headers which are allowed to be manually set are those which the Fetch spec defines as a CORS-safelisted request-header, which are:
    Accept
    Accept-Language
    Content-Language
    Content-Type (please note the additional requirements below)
The only type/subtype combinations allowed for the media type specified in the Content-Type header are:
    application/x-www-form-urlencoded
    multipart/form-data
    text/plain
If the request is made using an XMLHttpRequest object, no event listeners are registered on the object returned by the XMLHttpRequest.upload property used in the request; that is, given an XMLHttpRequest instance xhr, no code has called xhr.upload.addEventListener() to add an event listener to monitor the upload.
No ReadableStream object is used in the request.

Jeśli jesteś w stanie zrobić zapytanie trzymając się tych ograniczeń to CORSy się nie aktywują.

0

Zależy do czego Ci to potrzebne, bo możesz spróbować skonfigurować proxy dla danych endpointow:

https://stackoverflow.com/questions/37172928/angular-cli-server-how-to-proxy-api-requests-to-another-server

0

Próbowałem już wszystkiego, pisanie jakiegoś proxy zabawa z node headersami itd i nic także idk co się dzieje może to wina api

0

@szatkus:

{
  "/api/*": {
    "target": "https://www.cryptingup.com",
    "secure": false,
    "logLevel": "debug"
  }
}


 "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "configurations": {
            "production": {
              "browserTarget": "cryptoTask:build:production",
              "proxyConfig": "proxy.conf.json"
            },
            "development": {
              "browserTarget": "cryptoTask:build:development",
              "proxyConfig": "proxy.conf.json"
            }
          },
          "defaultConfiguration": "development"
0

@szatkus:

"serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "configurations": {
            "production": {
              "browserTarget": "cryptoTask:build:production",
              "proxyConfig": "src/proxy.conf.json"
            },
{
  "/api": {
    "target": "https://www.cryptingup.com",
    "secure": true,
    "changeOrigin": true,
    "logLevel": "debug"
  }
}

public getAssets(): Observable<IAsset[]> {
    return this.http.get<IAsset[]>('https://www.cryptingup.com/api/assets');
  }

Error jak w poście - nadal :/

1 użytkowników online, w tym zalogowanych: 0, gości: 1