Out now! Check out the Poll results: Do you have a Shopify store?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: CORS error when fetching storefront-banner

Solved

CORS error when fetching storefront-banner

obinecko
Shopify Partner
11 1 3

Hi iam trying to implement consent cookies banner for hydrogen, 
i have implemented everything according to tips
just getting CORS error when trying to fetch 

obinecko_0-1727265286373.png

any ideas what could this cause ? iam trying from locahost, i have elso deployed it to test env, but the cors error persist.
Thanks for any ideas !

Accepted Solution (1)
obinecko
Shopify Partner
11 1 3

This is an accepted solution.

Problem solved with changing public checkout domain

View solution in original post

Replies 10 (10)

Sam416
Shopify Partner
35 2 4

Hi @obinecko 
Please try to add a CORS header to the script that fetches the banner.

header('Access-Control-Allow-Origin: *');

header('Access-Control-Allow-Methods: GET, POST');

header("Access-Control-Allow-Headers: X-Requested-With");

 

Shopify Expert | E-commerce Specialist | Custom Shopify App Development | Shopify Theme Customization & Bug Fixing | Buy Me A Coffee| Hire me| Contact Me on WhatsApp
obinecko
Shopify Partner
11 1 3

But the script is loaded automaticly via <Scripts/>  from shopifycloud i cannot access the source code of the script.

obinecko
Shopify Partner
11 1 3

This is an accepted solution.

Problem solved with changing public checkout domain

soller
Shopify Partner
5 0 1

Hey @obinecko
I'm stuck in the same CORS problem

My public checkout domain appears to be - myshopifydomain/checkouts/cn/AbIgHashHeReXYz

How did you configure yours?

obinecko
Shopify Partner
11 1 3

try to check public_store_domain, does it match with yours myshopifydomain?

soller
Shopify Partner
5 0 1

Hi @obinecko 

In the documentation it says that I had to start the checkout in my store and copy the domain.
But it was only when I set my PUBLIC_CHECKOUT_DOMAIN to the same as PUBLIC_STORE_DOMAIN, as you said, that I managed to get the privacy banner to work..

I have the latest version of Hydrogen... did I look in the wrong documentation?

https://shopify.dev/docs/storefronts/headless/hydrogen/analytics/consent

Problem solved, thank you!

soller
Shopify Partner
5 0 1

Hey @obinecko 

I was able to see the cookie banner on localhost but I couldn't see it in production.
Can you help me with this too?
More info in the original post:
https://community.shopify.com/c/hydrogen-headless-and-storefront/shopify-cookie-banner-not-showing-u...

obinecko
Shopify Partner
11 1 3

I havent doployed it to prod yet,there are changes in varaintselector, which messed up ui, hopefully ill check it this week and let you know.

obinecko
Shopify Partner
11 1 3

but maybe check storefront env and vars, maybe there is some missmatch

soller
Shopify Partner
5 0 1

Yes, problem with environment variables is most likely. Anyway, I've already checked that they are correct in the admin. Maybe I have a problem in my environment...
Let me know when you deploy.
Thanks for the reply and if you need anything just ask.