on 01-28-2020 6:49 AM
how can i unblock the CORS policy and get access to electronics site. I am getting the following error.
Access to XMLHttpRequest at 'https://localhost:9002/rest/v2/electronics-spa/cms/pages?fields=DEFAULT&pageType=ContentPage&pageLabelOrId=homepage⟨=en&curr=USD' from origin 'http://localhost:4200' has been blocked by CORS policy: Request header field x-anonymous-consents is not allowed by Access-Control-Allow-Headers in preflight response.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you still have issues with your CORS settings on your backend, you can all the time use proxying-to-a-backend-serve in your dev ENV. This will proxy the call to your backend.
Here is an example of proxy.conf.json to proxy /api to a free api out there
{
"/api": {
"target": "https://api.openbrewerydb.org",
"pathRewrite": {
"^/api": ""
},
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try using the Spartacus Demo API by initialising your angular
B2cStorefrontModule.withConfig({
backend: {
occ: {
baseUrl:
'https://storefront.c39j2-walkersde1-d4-public.model-t.cc.commerce.ondemand.com',
},
},
context: {
urlParameters: ['baseSite', 'language', 'currency'],
baseSite: ['electronics-spa'],
},
If this works, then there might be an issue on how your backend responds. You can try to use something like cors-anywhere for debugging, but please don't use something like this in production.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I also encountered that error while following the Spartacus documentation. In my case, I was creating the Angular Project with schematics and that error showed up, then by switching into downloading the dependencies the Storefront run with no issues.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.