ipfs / service-worker-gateway

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

fix: ipfs-hosted redirects are not infinite #215

Closed SgtPooki closed 2 months ago

SgtPooki commented 2 months ago

Title

fix: ipfs-hosted redirects are not infinite

Description

Fixes https://github.com/ipfs-shipyard/service-worker-gateway/issues/211

Summary of changes

  1. Adds ipfs-gateway.js script that uses existing reverse-proxy (some updates were needed) to host static site via local kubo
  2. Updates ipfs-hosted tests in first-hit.test.ts to use the above test server, so we are no longer only getting a ?helia-sw request. This should get us 99% closer to actual functionality when hosted in environments like inbrowser.tld
  3. Resolves issues with infinite redirects by updating src/pages/redirects-interstitial.tsx and src/pages/redirect-page.tsx
  4. Moves out service worker & config provider from the initial landing page into each sub-page, which reduces the total assets sent on first-hit for each scenario.
  5. updates reverse-proxy logging to use @libp2p/logger, but it's not actually working for some reason

Notes & open questions

  1. I could use an extra set of eyes on the updated use of @libp2p/logger in reverse-proxy.js proxy-server logging fixed with 688594e (#215)
  2. Callout that maybe we don't want to display in RedirectsInterstitial because it's just going to be quick Flashes that aren't really visible, but on gateways where providing the assets are slow, it will be informative.
  3. If you set the playback speed to very slow on the demo video you can see the redirect cycle pretty clearly

Demo showing fix:

https://github.com/ipfs-shipyard/service-worker-gateway/assets/1173416/d06ebbd5-1270-4a21-9e5f-ba6a8f870791

Change checklist

SgtPooki commented 2 months ago

Thanks! Had no bandwidth today to review code, but if this data point is useful: I did run it locally against static http server and ?helia-sw=/ipns/docs.ipfs.tech and it no longer redirects to /ipns/docs.ipfs.tech so the infinite loop from #211 (comment) does not occur anymore.

The http-server hosted scenarios seemed fine. The _redirects logic with the newer redirects-interstitial.jsx page introduced the bug. This is why I had to implement local ipfs-gateway.js so that we could serve the site similarly to inbrowser.tld.

SgtPooki commented 2 months ago

merging to fix the bug on https://inbrowser.dev