I want to build a simple web app, running entirely...
# random
p
I want to build a simple web app, running entirely in the browser (no backend), to analyze publicly available files from another domain. Well, CORS stands in the way 😄 Is there any way to work around it, other than having my own proxy server, and making users install browser extensions like this one? I know this is basically not kotlin but kotlin colored as CORS is a generic mechanism in the browsers, but if it matters: I already have a working PoC in Kotlin/Wasm, maybe Wasm has some kind of a secret toggle?
@Stefan Oltmann @Robert Jaros curious if you know!
s
I don't know hacks around that. If the original host didn't set CORS rules that allow you to access the files, you may need to setup a proxy getting them - like a Cloudflare worker. But free tier is limited to 100k calls per day.
👍 2
I use this page to find out if a host has set CORS rules: https://cors-test.codehappy.dev/
thank you color 1
p
thanks for the idea with Cloudflare, this quota may be sufficient for my use case!
👍 1
s
If both domains are under your control you may also make a Cloudflare proxy using CNAME. CORS only steps in and annoys if domains differ. For example my https://stefan-oltmann.de/oni-seed-browser gets data from https://data.mapsnotincluded.org ... CORS steps in and annoys. I'm working on making a proxy on https://data.stefan-oltmann.de just to drop all this CORS configuration stuff.
CORS is enforced by the browser, so in my view it's a relatively weak protection system. 👀
true story 1
In that way a small hack I figured out: GitHub release page has strict CORS rules, but anything published to GitHub pages has CORS wildcard. 😉
p
For example my https://stefan-oltmann.de/oni-seed-browser gets data from https://data.mapsnotincluded.org ...
CORS steps in and annoys.
sorry, I missed something - given the seed browser works fine, what's the secret here? I see the app lazily loads next items, but I don't see anything in the Network tab - do you use web sockets or sth?
or is it all static content embedded into the app?
s
No, the map database is 5 GB 😄
p
let me actually share what I'm trying to achieve here, to avoid XY communication problem: I want to create a tool where one would specify Maven artifacts of a given Java/Kotlin (JVM) library, and the tool would enumerate all versions along with Java bytecode version (+ in the future: Kotlin metadata version). It's messy like a PoC, but it works, at least for my lib (tried with other libs, has some minor toubles, probably because of bespoke KMP ZIP + inflate), see the code
s
It loads from https://data.mapsnotincluded.org/ & https://oni-worlds.stefanoltmann.de/ as a mirror. You should see the calls in the network tab. On both backends I set a CORS wildcard rule to make it work.
👍 1
p
ah ok, so you control mapsnotincluded.org domain 🙂 that's what I've missed
👍 1
s
Yes, the service that's running there at least.
Here is your issue.
maven.org doesn't allow you to access. You will need the proxy.
👍 1
Or you ask them if they set wildcard CORS rules... Given Gradle can access from any client, they may be fine with that.
💡 1
p
I'll try it, I think they're pretty responsive when creating new Central accounts 😄
👍 1
p
ok, a request to Sonatype sent, let's see what happens
👍 1
s
Let me know what they respond. 🙂
👍 1
1
c
> CORS is enforced by the browser, so in my view it's a relatively weak protection system. Well, the point of CORS is to stop third-party sites from making actions against your website using the user's credentials. Proxying to a different origin doesn't create a risk of actions being accidentally authentified to the user, so CORS is protecting as intended.
👍 1
💯 1
☝🏻 1
j
Was about to say that 🙂 It works well, just annoying when it gets in the way 🙂
👍 2
p
@CLOVIS yeah, it's just weird to have CORS for resources that require no auth. But perhaps this way they're trying to cut off some traffic that the web apps with no backend (that are cheaper to create) might generate? Let's see what Sonatype responds, and how they justify their "no" (if it's a "no")
👆 1
Hello Piotr,
Thank you for your feedback. We will discuss it internally and let you know what we decide.
We would be interested in hearing more about your web-app project. We're always curious how our users integrate with Maven Central.
Thank you,
The Central Team
It's not a "no" yet, I hope :)
👍 1
s
Thanks for sharing. I don’t think they were ever asked that question. With CORS, you have to explicitly allow it — if they haven’t set anything up on their end, it’s forbidden by default.
👍 1
s
Very helpful. So indeed we don't need to set up our own CORS proxies. Nice.
p
oh, so there's an entire line of business here 😄
s
Indeed, some have pricing informations attached.