• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Question Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Voovvo

New Pleskian
Server operating system version
Centos 7
Plesk version and microupdate number
18.0.40 Update #1
I'm trying to add external payment method integration to my React app. I'm sending a fetch request to the external payment method's API application, but I'm getting the following error.

This is my fetch code.
JavaScript:
 async getPaymentsAccessToken() {
    const msg = await request<PaymentsAccessTokenResponse>(`https://apitest.crossdomain.com/accesstoken/get`, {
      method: 'POST',
      prefix: undefined,
      mode: 'cors',
      credentials: 'include',
      headers: {
        'Content-Type': 'application/json',
        client_id: this.client.client_id,
        client_secret: this.client.client_secret,
        'Ocp-Apim-Subscription-Key': this.client['Payments-Subscription-Key'],
      },
    });
    return msg;
  }

I got this error
Access to fetch at 'https://apitest.crossdomain.com/accesstoken/get' from origin 'mydomain.com' 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. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
None of the settings I made on Plesk Apache and Nginx work.

THIS ARTICLE NOT WORKING... !!!
https://support.plesk.com/hc/en-us/...s-origin-resource-sharing-in-Plesk-for-Linux-
 
Hi,

This is not necessarily a Plesk issue. You better post this on StackOverflow, where the React community can help you:

 
Hi,

This is not necessarily a Plesk issue. You better post this on StackOverflow, where the React community can help you:


But I got this error, Shouldn't this error have something to do with plesk?
Access to fetch at 'https://apitest.crossdomain.com/accesstoken/get' from origin 'mydomain.com' 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. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
 
Asking for help here every day isn't helpful. The lack of response on this topic is likely because of the fact this a specific issue to your setup which makes it hard for someone in the community to help you.

You'll have to do the trouble shouting yourself to find a solution to your problem. If you feel it's any issue with Plesk I suggest you contact Plesk support.
 
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "YOUR-DOMAIN.TLD"); // update to match the domain you will make the request from
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});

app.get('/', function(req, res, next) {
// Handle the get for this route
});

app.post('/', function(req, res, next) {
// Handle the post for this route
});


// this might help some one
 
Back
Top