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: redirect page and first-hit normalization #201

Merged
merged 6 commits into from
Apr 17, 2024

Conversation

SgtPooki
Copy link
Member

@SgtPooki SgtPooki commented Apr 15, 2024

Title

fix: redirect page and first-hit normalization

Description

Fixes config page loading and normalizes first hits landing on redirectPage.

Fixes #148
Fixes #150

Summary of changes

  1. Adds new page and shouldRender() function for _redirects interstitial page.
  2. Fixes config page loading on localhost.
  3. Removes redirect logic from service-worker context page. This is handled by the redirectPage.

Notes & open questions

This normalizes how redirects are handled. Now, the first hit on a redirect page will always land on the redirect page, and subsequent hits will be redirected to the target page. Previously, the first hit for ?helia-sw would actually load the helperUI page, which is not ideal.

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 15, 2024 that may be closed by this pull request
@SgtPooki SgtPooki changed the title fix: config is loaded properly on localhost fix: redirect page and first-hit normalization Apr 15, 2024
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

window.location.replace(windowLocation.href)
}

return (<>First-hit on IPFS hosted service-worker-gateway. Reloading</>)
Copy link
Member Author

Choose a reason for hiding this comment

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

we could probably add a spinner or something better here.

Comment on lines +20 to +34
/**
* If you host helia-service-worker-gateway on an IPFS domain, the redirects file will route some requests from
* `<domain>/<wildcard-splat>` to `https://<domain>/?helia-sw=<wildcard-splat>`.
*
* This function will check for "?helia-sw=" in the URL and modify the URL so that it works with the rest of our logic
*/
function translateIpfsRedirectUrl (urlString: string): URL {
const url = new URL(urlString)
const heliaSw = url.searchParams.get('helia-sw')
if (heliaSw != null) {
url.searchParams.delete('helia-sw')
url.pathname = heliaSw
}
return url
}
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 was moved from ipfs-hosted-redirect-utils.ts without modification


const routes: Route[] = [
{ default: true, component: LazyHelperUi },
{ path: '#/ipfs-sw-config', shouldRender: async () => (await import('./lib/routing-render-checks')).shouldRenderConfigPage(), component: LazyConfig },
{ shouldRender: async () => (await import('./lib/routing-render-checks')).shouldRenderRedirectPage(), component: LazyRedirectPage }
{ shouldRender: async () => (await import('./lib/routing-render-checks.js')).shouldRenderRedirectsInterstitial(), component: LazyInterstitial },
Copy link
Member Author

Choose a reason for hiding this comment

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

We could probably import this check function immediately since it's tiny but this is consistent at least.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds like a reasonable way to avoid an additional round trip.

@SgtPooki SgtPooki requested a review from a team April 15, 2024 21:45
@SgtPooki SgtPooki self-assigned this Apr 15, 2024
@SgtPooki
Copy link
Member Author

I need this in to fix config page loading on subdomains on localhost... will merge shortly.

@SgtPooki SgtPooki merged commit 8c85b6f into main Apr 17, 2024
20 checks passed
@SgtPooki SgtPooki deleted the 148-bug-iframe-loading-on-localhost3000 branch April 17, 2024 17:27
@lidel lidel mentioned this pull request Apr 17, 2024
@2color
Copy link
Member

2color commented Apr 18, 2024

Nice! From my testing this resolves the redirection loop.

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: path requests should not try to render iframe bug: iframe loading on localhost:3000
2 participants