Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ipfs-hosted redirects are not infinite #215

Merged
merged 8 commits into from
Apr 23, 2024
Merged

Conversation

SgtPooki
Copy link
Member

@SgtPooki SgtPooki commented Apr 23, 2024

Title

fix: ipfs-hosted redirects are not infinite

Description

Fixes #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:

2024-04-23.at.10.20.59.-.ipfs-hosted-redirect.mp4

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

@SgtPooki SgtPooki linked an issue Apr 23, 2024 that may be closed by this pull request
@SgtPooki SgtPooki self-assigned this Apr 23, 2024
@SgtPooki SgtPooki requested a review from a team April 23, 2024 17:30
Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self review

Comment on lines +56 to +65
await $(execaOptions)`${kuboBin} config Addresses.Gateway /ip4/127.0.0.1/tcp/${gatewayPort}`
await $(execaOptions)`${kuboBin} config Addresses.API /ip4/127.0.0.1/tcp/0`
await $(execaOptions)`${kuboBin} config --json Bootstrap ${JSON.stringify([])}`
await $(execaOptions)`${kuboBin} config --json Swarm.DisableNatPortMap true`
await $(execaOptions)`${kuboBin} config --json Discovery.MDNS.Enabled false`
await $(execaOptions)`${kuboBin} config --json Gateway.NoFetch true`
await $(execaOptions)`${kuboBin} config --json Gateway.DeserializedResponses true`
await $(execaOptions)`${kuboBin} config --json Gateway.ExposeRoutingAPI false`
await $(execaOptions)`${kuboBin} config --json Gateway.HTTPHeaders.Access-Control-Allow-Origin ${JSON.stringify(['*'])}`
await $(execaOptions)`${kuboBin} config --json Gateway.HTTPHeaders.Access-Control-Allow-Methods ${JSON.stringify(['GET', 'POST', 'PUT', 'OPTIONS'])}`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file could probably benefit from some optimizations from kubo folks.

cc @lidel @hacdias

@SgtPooki SgtPooki mentioned this pull request Apr 23, 2024
@SgtPooki
Copy link
Member Author

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
Copy link
Member Author

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

@SgtPooki SgtPooki merged commit 40cc8c7 into main Apr 23, 2024
20 checks passed
@SgtPooki SgtPooki deleted the 211-bug-infinite-redirect branch April 23, 2024 18:13
@lidel lidel mentioned this pull request Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: infinite redirect
2 participants