Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OTHER] How to use on Magento Cloud #78

Open
rahulblue opened this issue Jan 13, 2023 · 23 comments
Open

[OTHER] How to use on Magento Cloud #78

rahulblue opened this issue Jan 13, 2023 · 23 comments

Comments

@rahulblue
Copy link

rahulblue commented Jan 13, 2023

We have tried to installed your module into Magento Cloud, We followed all initial steps which you given. we were trying to add system variable which you mentioned here - https://github.com/graycoreio/magento2-cors/blob/master/docs/stories/configuring-the-headers.md, but in Magento cloud env.php file is not editable, also there isn't any provision to add system variable into anywhere.

Do you have any other solution for adding all values under system? adding somewhere in config or .php file?

Environment

magento2-cors version: 1.6.0
Magento version: Magento Commerce 2.4.5
PHP Version version: 8.1

@damienwebdev
Copy link
Member

damienwebdev commented Jan 13, 2023

@rahulblue you can make this work by using the cloud UI for managing ENV settings.

The relevant document would be:

https://experienceleague.adobe.com/docs/commerce-cloud-service/user-guide/configure/env/variable-levels.html?lang=en

https://devdocs.magento.com/guides/v2.3/config-guide/prod/config-reference-var-name.html

You'll need to set

env:CONFIG__SYSTEM__WEB__GRAPHQL__CORS_ALLOWED_ORIGINS

as well as other relevant configuration in the UI.

@damienwebdev
Copy link
Member

Additionally, I would recommend giving 2.0 a try as well, it's ~10x faster than the 1.x line.

@rahulblue
Copy link
Author

env:CONFIG__SYSTEM__WEB__GRAPHQL__CORS_ALLOWED_ORIGINS

I have tried using this method but again having a same problem
3795a25e-9fa7-4daf-870a-0a2612c20013
.
b359b61d-6a3c-40c3-8636-499f1ea9e3c4

@damienwebdev
Copy link
Member

Please re-read the documents I sent.

@rahulblue
Copy link
Author

Exactly which point are you referring to the problem is in there is no .magento.env.yaml file in the setup, only way I have that creating environment variable from Cloud UI, but it is not working. I am researching this topic since from last 9 hour still do not have exact solution.

@damienwebdev
Copy link
Member

https://devdocs.magento.com/guides/v2.3/config-guide/prod/config-reference-var-name.html#variable-names

Additionally, take a look at your screenshot and try to align:

  1. What you wrote in the variable name
  2. What you pasted into the variable value
  3. What I wrote in the docs for the variables of this repo

It looks like you literally copy-pasted some access control headers into the field, which I don't mention anywhere in my docs.

@rahulblue
Copy link
Author

rahulblue commented Jan 13, 2023

Thanks for your reply,

Can you see below screenshot? Am I missing or doing wrongly?

please suggest.

a9c831ba-e1ee-4ede-ac49-06c6e88695ca
f2e7d76b-4275-459d-a530-5f8f1a0136d3

@damienwebdev
Copy link
Member

@rahulblue looks much better, however there's an error in your key name DEFAUT vs. DEFAULT

@rahulblue
Copy link
Author

No luck after updating.

same error
334f03d3-3adb-4bd4-8515-14413dad6d28
7100c28a-602f-4fdc-b5c4-cd29b539499e

@damienwebdev
Copy link
Member

Ok, let me try this out and I'll post my findings.

@rahulblue
Copy link
Author

please let me know your findings, I have only one hope which is your extension. for Magento cloud integration branch there is no other way to enable CORS settings, it would be enable on further environment(Staging and Production) due to fastly. currently it is a biggest bottleneck for moving ahead to me.

Thanks.

@damienwebdev damienwebdev changed the title [OTHER] [OTHER] How to use on Magento Cloud Mar 17, 2023
@leandrofreireasco
Copy link

@damienwebdev any update on this one? Having the same issue here

@damienwebdev
Copy link
Member

damienwebdev commented Apr 5, 2023 via email

@leandrofreireasco
Copy link

leandrofreireasco commented Apr 5, 2023

@damienwebdev I'm working on a cloud project right now.
Our stack is Angular (Frontend) and Magento Cloud.
We are getting issues with CORS while trying to fetch data from a graphql endpoint.
I've installed your module and tried to configure it:

  • Environment variables:
    -- CONFIG__DEFAULT__WEB__GRAPHQL__CORS_ALLOWED_ORIGINS
    -- CONFIG__DEFAULT__WEB__GRAPHQL__CORS_ALLOWED_METHOD

  • Adding to the app/etc/config.php (we don't have access to the env.php in Magento Cloud)

  • Adding the XML paths directly into the core_config_data table

None of the steps above works

Any other clue on what we could do?

@damienwebdev
Copy link
Member

damienwebdev commented Apr 5, 2023

Can you include the output headers on an OPTIONS request with curl targeted at your domain?

curl https://DOMAIN.com/graphql \
   -X OPTIONS \
   -H "Access-Control-Request-Method: POST" \
   -H "Access-Control-Request-Headers: content-type" \
   -H "Origin: https://DOMAIN.com" \
   --head

Please change the domain above and post the response you get back.

Additionally, please post the content you used for your ENV settings.

Finally, if you have a local env, can you confirm if it works locally in your environment. It may well be that Fastly messes with requests in cloud.

@leandrofreireasco
Copy link

leandrofreireasco commented Apr 6, 2023

@damienwebdev just to let you know, I figured it out.

In order for this module to work with Magento Cloud, we need to add the following entries to the app/etc/config.php file:

 'system' => [
        'default' => [
            'web' => [
                'graphql' => [
                    'cors_allowed_origins' => '*',
                    'cors_allowed_methods' => 'GET, POST, OPTIONS, PUT',
                    'cors_allowed_headers' => 'Content-Type, GraphQLAuth', // All headers used in the request
                    'cors_max_age' => '86400',
                    'cors_allow_credentials' => 0
                ],
                'api_rest' => [
                    'cors_allowed_origins' => '*',
                    'cors_allowed_methods' => 'GET, POST, OPTIONS',
                    'cors_allowed_headers' => 'Content-Type, GraphQLAuth' // All headers used in the request,
                    'cors_max_age' => '86400',
                    'cors_allow_credentials' => 0
                ]
            ]
        ]
    ]

@damienwebdev
Copy link
Member

What wound up being the problem, the allowed headers?

@leandrofreireasco
Copy link

yep, those 3 headers must exist:

  • cors_allowed_origins
  • cors_allowed_methods
  • cors_allowed_headers

@damienwebdev
Copy link
Member

@leandrofreireasco ok. Then, for the origins, I assume you added those as ENV variables to the cloud UI? Could you add a screenshot of what you added? (Feel free to obfuscate this, I just need a screenshot for the documentation)

@damienwebdev
Copy link
Member

pinging @leandrofreireasco just one more time in hopes of a screenshot :)

@amcguireweb
Copy link

Funny you mention "for the documentation", I literally see no documentation to use this with Cloud. Trying to piece together a couple random issues with no solutions isn't working. Uninstalled as fast as I installed it.

@damienwebdev
Copy link
Member

Sorry @amcguireweb I don't have any merchants that use this on Commerce Cloud. If you're willing to hop in discord, I'd be happy to turn whatever comes out of that into docs, it's just hard to write docs for something I don't do!

@leandrofreireasco
Copy link

Here we go @damienwebdev

app/etc/config.php

image

.magento.app.yaml

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants