1

I'm attempting to send a POST request to a Magento 2 API that my co-worker launched. It's up and working. I've been able to get a response via curl, but because of pre-flight requests from the client I haven't been able to get a response.

Now, I know about the headers. We have 'Access-Control-Allow-Origin': '*' set already. The issue is that the OPTIONS request is being sent to determine the safety of the request (see here). Is there a way to handle this pre-flight OPTIONS request? If so, how?

Here's the other thing: my co-worker is receiving a response via curl, Ajax, and Ember. 🤔

0

1 Answer 1

1

A CORS preflight request is a CORS request that checks to see if the CORS protocol is understood.

It is an OPTIONS request, using three HTTP request headers: Access-Control-Request-Method, Access-Control-Request-Headers, and the Origin header.

A preflight request is automatically issued by a browser when needed. In normal cases, front-end developers don't need to craft such requests themselves.

Reference: https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request

Magento 2 Api does not support pre-flight request by default. You can modify the apache or nginx server config for handling the request. For example http://snippi.com/s/or2myzn

I would suggest installing the following module for handling the CORS pre-flight request in Magento 2 Api: https://github.com/splashlab/magento-2-cors-requests

Not the answer you're looking for? Browse other questions tagged or ask your own question.