CORS origin Error
Hello Guys
when I try to fetch data using API i got same CROS origin error on console
can you give some idea how to solve this error
15 Replies
Hello @rohrig @skirianov sir can you please check once 😊
You need to add localhost to allowed origins on the magento cloudways app
General speaking: it’s always best, to set these origins - on production, to only your frontend url
In this case for localhost it needs the full domain + port: http://localhost:3000
i do that also but it did not fetch the product
@FabianClemenz what i have to do
i have to fetch pop art categories product on this location that i mention on screen shot
what can i do for that
@Altamash it's hard to say what's going on exactly, are you fetching magento directly from frontend avoiding middleware?
@skirianov so what is simple way to fetch categories product on this page
can you show me how you fetch it?
If we are talking about Nuxt2 version, you need to use our composables
useProduct composable | Vue Storefront 2 for Magento
Documentation for the Magento connector for Vue Storefront 2
@skirianov i try to fetch using magento API
oh....you're not using Vue Storefront Middleware and composables?
We have them prepared for you to handle all the requests and responses and they are covering most of the base use cases like fetching data and basically all other things
Please read this one https://docs.vuestorefront.io/magento/composition/composables.html
Everything is already handled for you, unless you want something custom
Composables | Vue Storefront 2 for Magento
Documentation for the Magento connector for Vue Storefront 2
@skirianov i try to do it with middleware also but it not solved
I'm a bit lost right now, sorry.
What exactly are you trying to do. Is it something custom that is not handled by composables?
I see you created a new ApiMethod, where do you call this method later on?
forget all other method @skirianov sir
only what i have to do i want to fetch my pop art categories product
so which is simple way to that
https://docs.vuestorefront.io/magento/composition/use-product.html#search-products
This will get you a list of all products. You can filter products by categories by using filter option.
getProductList({
filter: {
category_uid: << INSERT THE CATEGORY UUID HERE >>
}
})
useProduct composable | Vue Storefront 2 for Magento
Documentation for the Magento connector for Vue Storefront 2