-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: redirect page and first-hit normalization (#201)
* fix: helia-sw? and other first-hits are handled the same * fix: iframe config is loaded on first-hit * chore: apply suggestions from code review * fix: build after preact migration
- Loading branch information
Showing
9 changed files
with
407 additions
and
1,154 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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</>) | ||
} | ||
|
||
/** | ||
* 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters