Finally got a chance to try this and while it looks like it works in a browser (ie: incognito mode), there are CORS issues if using it from a frontend.
One thing to keep in mind is whatever server youâre running, its defaults may not include CORS headers, so you may need to modify your server configuration to enable CORS
Weâre setting the right CORS headers, the exact same code running on GitHub Codespaces works. Even running our frontend on IDX and the backend on Codespaces works.
Just weighing in further that I tested with a simple Node.js app and CORS headers seemed to work fine, so more details about your setup would be very helpful.
Here are my steps to validating that CORS did work:
Make the preview public using the new âMake Preview Publicâ button under the link icon in the web preview (as Node is serving on the preview port, 9000). For now we also expose the raw âUpdate Public Portsâ command (will go away soon)
Observe that while cURL in the terminal returns the âhello worldâ HTML as expected:
$ curl https://9000-therestoftheurl
Opening up the DevTools in a browser tab and trying to fetch:
First, I hope you donât remove the update ports command and expect people to use the web preview to do it. I donât use it and I suspect others wonât either.
Second, did you actually make a second workspace to do the fetch from? Doesnât sound like it from your description.
Re #1: I shouldâve clarified â thereâs also a little lock icon (see this other post for a screenshot) thatâll let you mark any other port with a running server as public too (not just the preview port).
Re #2: Great point, I just tried that (unauthenticated fetch from the web preview) and it DOES work. So I do think thereâs something else going on in your workspace, that we need to troubleshoot
Hrm, I tried that exact cors go package configuration and it still seemed to work for me.
A couple things thatâd be helpful:
Which port # are you exposing?
Which container commit or permanent tag are you on?
To find this, open the IDX panel on the left (Focus on Project IDX View in the command palette), click the Support icon, and look at the menu on top. Hopefully it should be something like 924e7d (container commit) and cool-noyce-93 (permanent tag)
Is there anything notable about your Google account (e.g. part of a Google Workspace organization, etc), or are you logging in with a plain olâ Gmail/etc account?
Hm, yeah that all looks right, and I verified in my own workspace that switching from the preview port to 8080 still works.
Apologies that things arenât working and thanks for trying this out⊠I think the next step is to file a bug in our tracker. also /cc @Chandra_Sekhar_Pydi in case you have ideas
Found the problem! Thanks so much for helping us identify it. In short, one of our proxies is removing CORS headers (e.g. Access-Control-Allow-Origin) in the HTTP response for the browserâs OPTIONS request (aka âpreflightâ, which are used for POST requests).
I havenât found a good workaround yet, but weâll follow up in the bug you filed (thank you!). Hopefully this is something we can resolve shortly.
EDIT: I updated the bug title and added repro steps, will now follow up with our infra teams on this.
Hey folks, while weâre hard at work addressing the CORS issue above, I also wanted to call out that we also have a new easy way to make the port running your web previews public:
Open the Share Preview Link menu in the web preview toolbar
Select Make Preview Public
The icon will change to a yellow globe indicating itâs public
Click to open up the menu again and Remove Public Access when you want to turn it off.
Also a reminder that ports are only accessible when your workspace is active, so this isnât really intended as a web hosting solution â but itâs a great way to quickly share your app with a teammate for feedback!