-
Notifications
You must be signed in to change notification settings - Fork 12
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
Changes from all commits
d4e692d
8c7c6a2
1dcd51c
07d77b6
aea7736
b9df5f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'preact' | ||
|
||
/** | ||
* This page is only used to capture the ?helia-sw=/ip[fn]s/blah query parameter that | ||
* is used by IPFS hosted versions of the service-worker-gateway when non-existent paths are requested. | ||
*/ | ||
export default function RedirectsInterstitial (): React.JSX.Element { | ||
const windowLocation = translateIpfsRedirectUrl(window.location.href) | ||
if (windowLocation.href !== window.location.href) { | ||
/** | ||
* We're at a domain with ?helia-sw=, we can reload the page so the service worker will | ||
* capture the request | ||
*/ | ||
window.location.replace(windowLocation.href) | ||
} | ||
|
||
return (<>First-hit on IPFS hosted service-worker-gateway. Reloading</>) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could probably add a spinner or something better here. |
||
} | ||
|
||
/** | ||
* 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 | ||
} | ||
Comment on lines
+20
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was moved from ipfs-hosted-redirect-utils.ts without modification |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.