single-spa / create-single-spa

https://single-spa.js.org/docs/create-single-spa
Other
128 stars 60 forks source link

CORS issue with Swapi API #69

Closed protoEvangelion closed 4 years ago

protoEvangelion commented 4 years ago

Getting this error when generating a react application & when going directly to the example react microfrontend: https://react.microfrontends.app/people

image

I'm not sure if the SWAPI api is down or if it's actually a CORS issue.

When navigating to the swapi docs page or api, it looks like a blank heroku site:

https://swapi.co/documentation

joeldenning commented 4 years ago

Hi @protoEvangelion, I believe this is due to Content-Security-Policy. See https://github.com/single-spa/create-single-spa/pull/44 and this documentation. If you would rather not deal with CSP and just want things to work, you can comment out or remove the content security policy.

https://github.com/single-spa/create-single-spa/blob/646092d6e2649716c799fd09c6e6eda91eaf317b/packages/generator-single-spa/src/root-config/templates/src/index.ejs#L8-L12

cc @filoxo, who authored this. I am closing this issue because there is no bug here. But feel free to comment further or reopen.

protoEvangelion commented 4 years ago

@joeldenning Thanks for the docs & explanation. There is no CSP meta tag though in the demo repo: https://github.com/react-microfrontends/root-config/blob/master/src/index.ejs

image

Not a huge deal but it would be nice if the recommended demo repo worked for newcomers like myself :)

joeldenning commented 4 years ago

Oops I misread this! This is a CORS error, not CSP!

There is nothing that we could do to make the swapi API work with CORS. The swapi API itself would have to send the correct CORS response headers in order for you to be able to call it.

joeldenning commented 4 years ago

You can read more about CORS at https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS - it is something that is implemented by the browser, not single-spa.

filoxo commented 4 years ago

Actually, this appears to just be that swapi is no longer working. The readme even says that it's no longer maintained: https://github.com/phalt/swapi

Edit: I'll open up a new issue on the react-microfrontends repo and discuss ideas for what to do.

joeldenning commented 4 years ago

Oh haha good catch I didn’t even realize that it was our code calling swapi. This must have stopped working recently.

I’ve been wrong a couple times on this. Yes let’s fix this - I see you create an issue over in the example repo.