ipfs / service-worker-gateway

[WIP EXPERIMENT] IPFS Gateway implemented in Service Worker
https://inbrowser.link
Other
17 stars 8 forks source link

Improve subdomain detection logic #249

Open lidel opened 1 month ago

lidel commented 1 month ago

Problem: brittle subdomain mode support detection

Right now we make request to bafkqaaa on subdomain via fetch:

https://github.com/ipfs-shipyard/service-worker-gateway/blob/289aca764da893789508c56d7f9e0caeb5711d90/src/lib/path-or-subdomain.ts#L35-L39

This is too brittle, because it will likely break once people start deployign their own instances without doing all the steps we did:

Solution: switch to img onload

We should have a static /1x1.png in public/ and request that asset specifically.

This solves two problems:

SgtPooki commented 1 month ago

This will also resolve the "test this once" todo because it will be cached and return instantly with subsequent requests.

SgtPooki commented 1 month ago

one gotcha with the suggested fix is that this is also called from sw.ts code, and image onload won't work there, so we won't be able to do redirects from sw anymore, which will result in a little more assets rendered than we need.. but we have the redirect already working in client side code so it shouldn't break anything.