0

In Magento Cloud hosting, how to add following configuration,

Header set Access-Control-Allow-Origin a.com

When I login to Magento Cloud I have only read access to the server files. Is there a way to do this.?

2
  • if your server settings and files are managed by someone else , there is no point in this question here, ask your hosting support.
    – MagenX
    Commented Feb 26, 2018 at 9:15
  • You can do that using app/etc/env.php by allowing CORS(make sure file is not in git ignore)or by updating your fastly to allow CORS, hope that helps Commented Dec 6, 2023 at 18:35

2 Answers 2

0

I would suggest installing the below module via the composer

https://github.com/graycoreio/magento2-cors/blob/master/docs/stories/configuring-the-headers.md

and apply those configurations in the app/etc/config.php

'system' => [
        'default' => [
            'web' => [
                'graphql' => [
                    'cors_allowed_origins' => 'https://www.graphql.com, https://www.myotherallowedorigin',
                    'cors_allowed_methods' => 'POST, OPTIONS',
                    'cors_allowed_headers' => '',
                    'cors_max_age' => '86400',
                    'cors_allow_credentials' => 1
                ],
                'api_rest' => [
                    'cors_allowed_origins' => 'https://www.restapi.com, https://www.myotherallowedorigin',
                    'cors_allowed_methods' => 'GET, POST, OPTIONS',
                    'cors_allowed_headers' => '',
                    'cors_max_age' => '86400',
                    'cors_allow_credentials' => 0
                ]
            ]
        ]
    ]

Cheers!

-1

With Magento Cloud, depending on whether the environment you are looking at has Fastly or not, there could be different solutions.

Global solution
You can use Magento itself to set that header - by creating an extension to set the desired header on all/some of the responses.

NGINX solution
I believe the engineering team can help by raising a support ticket to instruct them to config the NGINX instruction to set this header.

Fastly solution
This is only applicable if the environment you are referring to has Fastly integrated. Since we don’t have direct access to out Fastly account. You will have to config the add header instruction into custom VCL yourself via API call with provided Fastly API credentials. Or raise a support ticket with Magento Cloud to help you setting this custom VCL.

More information regarding Fastly configuration API: https://docs.fastly.com/api/config

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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