-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle helia-sw query from _redirects (#67)
- Loading branch information
Showing
3 changed files
with
58 additions
and
14 deletions.
There are no files selected for viewing
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,15 @@ | ||
/** | ||
* 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 | ||
*/ | ||
export 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 | ||
} |