CORS error when fetching storefront-banner

Solved

CORS error when fetching storefront-banner

obinecko
Shopify Partner
9 1 2

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
9 1 2

This is an accepted solution.

Problem solved with changing public checkout domain

View solution in original post

Replies 6 (6)

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
9 1 2

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

obinecko
Shopify Partner
9 1 2

This is an accepted solution.

Problem solved with changing public checkout domain

soller
Shopify Partner
2 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
9 1 2

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

soller
Shopify Partner
2 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!