Is there any recommended way right now to display ...
# compose-web
j
Is there any recommended way right now to display images in a Wasm based Compose for Web client without running in to CORS issues?
v
Hey John, actually I'm not a web expert, but as far as I know, "CORS" means that the owner of the resource is not allowing it to be displayed on other web page (it's being blocked by the browser). So, two options come to mind: 1. Ask the owner to whitelist your host. 2. For development purposes only: add a proxy for resources. The easiest way for me is to use a Heroku server:
<https://cors-anywhere.herokuapp.com/[your> blocking URL]
ex: insted of calling
<https://third-party.com/image.jpg>
call
<https://cors-anywhere.herokuapp.com/https://third-party.com/image.jpg>
👍 1
Another option is to run Chrome with security disabled. On macOS, you can do this by running the following command:
Copy code
open -n -a /Applications/Google\ <http://Chrome.app/Contents/MacOS/Google\|Chrome.app/Contents/MacOS/Google\> Chrome --args --user-data-dir="/tmp/chrome_dev_test" --disable-web-security
👍 1
j
Thanks @Vram Voskanyan, we could do something like that but was more wondering about something like javascript fetch api that can use
no-cors
mode
h
You can’t disable cors in the browser using JS, that’s the whole point of cors.
👍 1
4
☝️ 1
👍🏾 1
j
Understand that.....had thought for some reason there was way to not have that constraint for something like fetching of static images......and had seen reference to that
no-cors
mode that fetch api has....anyway, it seems like some kind of proxy is way to go here
👍 1
b
To be precise, you can make a fetch request with no-cors (see mode option), but in an application (inside the browser) you will get a dummy response — IIRC, no content, no headers, status code = 0, and so on.
👍 2
c
The
no-cors
is really meant to send a message out without expecting any data coming back, like for analytics. CORS is very odd, as we only deal with this in web browsers. The best way around it is to use a public proxy that is backed by a CDN (like http://wsrv.nl), a service that serves public images (like some of the photo sites) or your own server where you can set the CORS values. The CORS must be set up on the server. There is no configuration allowed on the browser side to bypass this. This is all the purpose of CORS and it’s annoying, and I’m not sure how much it prevents what it’s intending to prevent… lol
👍 2