Skip to content

CORS Setup

Cross-Origin Resource Sharing (CORS) is a browser security feature that restricts web pages from making requests to a different domain than the one serving the page. CORS is required when your storefront runs on a different domain or port than your Adobe Commerce backend.

PaaS only

Quick test: Is CORS working?

Adobe Commerce uses /graphql as the GraphQL endpoint, and this is the primary endpoint that requires CORS configuration. If you already have CORS configured, test it by replacing YOUR_STOREFRONT_URL with your actual frontend URL:

curl -I -X OPTIONS https://your-commerce-backend.com/graphql \
-H "Origin: YOUR_STOREFRONT_URL" \
-H "Access-Control-Request-Method: POST"

Look for these headers in the response:

  • Access-Control-Allow-Origin: YOUR_STOREFRONT_URL (or * if using a wildcard)
  • Access-Control-Allow-Methods: GET, POST, OPTIONS

If you see these headers with your storefront URL, CORS is configured correctly. If not, follow the setup steps below.

Quick steps

Add CORS support

To add CORS headers to your Adobe Commerce GraphQL endpoints, you have several options:

  • Server configuration: Configure CORS headers at the web server level (Nginx, Apache)
  • Third-party module: Use a community module such as graycore/magento2-cors
  • Custom module: Implement a custom Adobe Commerce module to add CORS headers

Refer to your chosen implementation’s documentation for specific configuration steps.

Configure CORS settings

Configure your CORS implementation to allow requests from your storefront domain(s) to your Adobe Commerce GraphQL endpoint.

At minimum, you’ll need to configure:

  • Allowed origins: Your storefront domain(s) (for example, http://localhost:3000, https://your-storefront.com)
  • Allowed methods: GET, POST, OPTIONS
  • Allowed headers: Content-Type, Authorization, X-Requested-With

Refer to your chosen implementation’s documentation for specific configuration steps.

Test your CORS configuration

Open your storefront in a browser and check the Network tab in DevTools:

  • Look for preflight OPTIONS requests to your GraphQL endpoint
  • Verify the response includes headers like:
    • Access-Control-Allow-Origin: <your-storefront-url> (or * if using a wildcard)
    • Access-Control-Allow-Methods: GET, POST, OPTIONS
    • Access-Control-Allow-Headers: Content-Type, Authorization

If configured correctly, your GraphQL requests should succeed without CORS errors.

Common pitfalls

Next steps

If you encounter issues or need detailed configuration guidance, see CORS Troubleshooting

References