infor-cloud / m3-h5-sdk

https://infor-cloud.github.io/m3-h5-sdk/
36 stars 20 forks source link

CORS error response from IonApiService #18

Closed anhallbe closed 4 years ago

anhallbe commented 4 years ago

Describe the bug The ION API server returns an error when sending POST-requests through the IonApiService during development (odin serve).

The server responds with a status 400, and the body:

{
  "error": "CORS error - Origin is invalid"
}

To Reproduce Call IonApiService.execute() like so:

this.ionApiService.execute({
  method: 'post',
  url: 'some/api/path',
  responseType: 'json',
  source: 'something',
}).subscribe(
  () => log("success"),
  () => log("error"),
)

When this is executed, "error" is logged.

Expected behavior The above code should log "success".

Version

anhallbe commented 4 years ago

Update: It seems like the ION API service rejects requests from origins with http://. A workaround (until a fix is added to the CLI) is to add the Origin header in odin.json:

    "/ODIN_DEV_TENANT": {
      "target": "https://ionapi-server-address",
      "secure": false,
      "headers": {
        "Origin": "https://localhost"
      },
      "changeOrigin": true,
      "pathRewrite": {
        "^/ODIN_DEV_TENANT": "/MY_TENANT"
      },
      "logLevel": "debug"
    }
alliancehaydenm commented 4 years ago

Hi there - having the same issue in Odin 2.2.1, Angular 7. Have tried the above workaround. image

I'm trying to call an ION datalake API at this endpoint. Any advice? https://mingle-ionapi.se2.inforcloudsuite.com/ALLIANCEGRP_DEV/IONSERVICES/datalakeapi/v1/compass/jobs?resultFormat=text/csv

Error: Access to XMLHttpRequest at 'https://mingle-ionapi.se2.inforcloudsuite.com/ALLIANCEGRP_DEV/IONSERVICES/datalakeapi/v1/compass/jobs?resultFormat=text/csv' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. [http://localhost:8080/]

image

anhallbe commented 4 years ago

A fix has been added in version 3.0.0-next.4.

Amiin29 commented 3 years ago

Hi guys you have an idea to make a configuration on m3 w to enable the url or I let CORS desable to give access to all the url because i have the same issue and I think the revolution of this problem is this idea

karinpb commented 3 years ago

@Amiin29 Please stop commenting on tickets that are closed. Follow the documentation and samples to get started. You cannot call any endpoint directly in development, you need to use the proxy. What I can see from previous comments you are trying to call the M3 rest directly, it will never work. Take the latest version, use the proxy and if you find an issue be sure that you are following the samples and then create a ticket with a lot of information about all the steps that you have taken.

Amiin29 commented 3 years ago

use the proxy and if you find an issue be sure that you are following the samples and then create a ticket with a lot of information about all the steps that you have taken.

thank you for your answer it is running correctly

Amiin29 commented 3 years ago

use the proxy and if you find an issue be sure that you are following the samples and then create a ticket with a lot of information about all the steps that you have taken.

thank you for your answer it is running correctly and I apologize because I comment on the tickets that are closed