Skip to content

Commit 61eea77

Browse files
authored
fix: structural overhaul (#906)
Refactors routing code to greatly simplify architecture. 1. Document the loading process 1. Display server error/fetch error/origin isolation warning inline 1. Encode query parameters in redirect param 1. Make styling consistent across all pages 1. Add load/about/settings navigation above the fold to reduce on-screen clutter 1. Fix input form error so the 'load content' button shows 1. Allow hard refresh with query params 1. Pre-fill download input with CID/path from current page if available 1. Remove "first-hit" scaffolding as it covers up a query string parsing bug 1. Remove unused code and components 1. Add `waitUntil` to `page.goto` in playwright tests to fix race conditions where we expect a 200 status but it can still be redirecting 1. Disable Firefox bounce tracking protection during tests as it deletes the service worker when triggered
1 parent 5b649a8 commit 61eea77

File tree

89 files changed

+2417
-2569
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+2417
-2569
lines changed

README.md

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ and the [`verified-fetch` library](https://github.com/ipfs/helia-verified-fetch)
2626
within a [Service Worker](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API)
2727
to facilitate direct verified retrieval of content-addressed data.
2828

29-
A Service Worker is registered on the initial page load, and then intercepts HTTP requests
30-
for content stored on IPFS paths such as `/ipfs/*` (immutable) and
31-
`/ipns/*` (mutable) and returns
32-
[`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) objects
33-
to the browser.
29+
A Service Worker is registered on the initial page load, and then intercepts
30+
HTTP requests for content stored on IPFS paths such as `/ipfs/*` (immutable) and
31+
`/ipns/*` (mutable) and returns [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
32+
objects to the browser.
3433

3534
It functions as an IPFS gateway within the browser, offering enhanced security
3635
([hash verification](https://docs.ipfs.tech/concepts/content-addressing/)
@@ -98,15 +97,18 @@ With reverse-proxy:
9897
Without reverse-proxy:
9998
* `http://localhost:8345` - The service worker gateway front-end served directly with esbuild.
10099

101-
For the above URLs with reverse-proxy, the reverse proxy ensures subdomain support. This ensures you can access URLs like `https://<hash>.ipfs.localhost:<port>/` and `https://<dnslink>.ipns.localhost:<port>/`
100+
For the above URLs with reverse-proxy, the reverse proxy ensures subdomain
101+
support. This ensures you can access URLs like `https://<hash>.ipfs.localhost:<port>/`
102+
and `https://<dnslink>.ipns.localhost:<port>/`
102103

103-
As you type in a content path, you will be redirected to appropriate URL (typically that means [subdomain style resolution](https://docs.ipfs.tech/how-to/gateway-best-practices/#use-subdomain-gateway-resolution-for-origin-isolation)).
104+
As you type in a content path, you will be redirected to appropriate URL
105+
(typically that means [subdomain style resolution](https://docs.ipfs.tech/how-to/gateway-best-practices/#use-subdomain-gateway-resolution-for-origin-isolation)).
104106

105107
For more information about local development setup, see [/docs/DEVELOPMENT.md](/docs/DEVELOPMENT.md).
106108

107109
### Try hosted instance
108110

109-
We provide a public good instance of this projct configured to run in [subdomain mode](https://docs.ipfs.tech/how-to/address-ipfs-on-web/#subdomain-gateway),
111+
We provide a public good instance of this projct configured to run in[subdomain mode](https://docs.ipfs.tech/how-to/address-ipfs-on-web/#subdomain-gateway),
110112
aiming to be a drop-in replacement for `dweb.link`:
111113

112114
- 🚧 **WIP: alpha quality** https://inbrowser.link hosts the `release` branch, with a stable [release](https://github.com/ipfs/service-worker-gateway/releases)
@@ -120,21 +122,31 @@ aiming to be a drop-in replacement for `ipfs.io`:
120122

121123
#### Deploying to `production` and `staging`
122124

123-
Deploying to [production](https://github.com/ipfs/service-worker-gateway/actions/workflows/deploy-to-production.yml) and [staging](https://github.com/ipfs/service-worker-gateway/actions/workflows/deploy-to-staging.yml) is done by manually running the deployment action and passing the release version to the action.
125+
Deploying to [production](https://github.com/ipfs/service-worker-gateway/actions/workflows/deploy-to-production.yml)
126+
and [staging](https://github.com/ipfs/service-worker-gateway/actions/workflows/deploy-to-staging.yml)
127+
is done by manually running the deployment action and passing the release
128+
version to the action.
124129

125130
## Manual Service Worker Deregistration
126131

127-
In some cases, you might want to manually unregister or remove the Helia service worker from your browser. This can be useful for debugging purposes or to ensure a clean state.
132+
In some cases, you might want to manually unregister or remove the Helia service
133+
worker from your browser. This can be useful for debugging purposes or to ensure
134+
a clean state.
128135

129-
You can instruct the service worker to unregister itself by appending the `?ipfs-sw-unregister=true` query parameter to the URL of any page controlled by the service worker.
136+
You can instruct the service worker to unregister itself by appending the
137+
`?ipfs-sw-unregister=true` query parameter to the URL of any page controlled by
138+
the service worker.
130139

131-
For example, if the service worker is active for `https://example.com`, navigating to `https://example.com/?ipfs-sw-unregister=true` will cause the service worker to unregister itself and attempt to reload all controlled clients (browser tabs).
140+
For example, if the service worker is active for `https://example.com`,
141+
navigating to `https://example.com/?ipfs-sw-unregister=true` will cause the
142+
service worker to unregister itself and attempt to reload all controlled clients
143+
(browser tabs).
132144

133-
This option is also available via a button on the service worker's configuration page (`#/ipfs-sw-config`).
145+
This option is also available via a button on the service worker's configuration
146+
page (`#/ipfs-sw-config`).
134147

135148
## License
136149

137-
This project is dual-licensed under
138-
`SPDX-License-Identifier: Apache-2.0 OR MIT`
150+
This project is dual-licensed under `SPDX-License-Identifier: Apache-2.0 OR MIT`
139151

140152
See [LICENSE](./LICENSE) for more details.

build.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function gitRevision () {
5959
}
6060

6161
/**
62-
* Inject all ipfs-sw-*.html pages (not index.html and not ipfs-sw-first-hit.html) in the dist folder with CSS, git revision, and logo.
62+
* Inject all ipfs-sw-*.html pages (not index.html) in the dist folder with CSS, git revision, and logo.
6363
*
6464
* @param {esbuild.Metafile} metafile - esbuild's metafile to extract output file names
6565
* @param {string} revision - Pre-computed Git revision string
@@ -343,7 +343,6 @@ export const buildOptions = {
343343
'src/index.tsx',
344344
'src/sw.ts',
345345
'src/app.tsx',
346-
'src/error.tsx',
347346
'src/ipfs-sw-*.ts',
348347
'src/ipfs-sw-*.css'
349348
],

main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,16 @@ func redirectToHelia(w http.ResponseWriter, r *http.Request) {
6565

6666
func ipfsLikeHandler(w http.ResponseWriter, r *http.Request) {
6767
if fileExists(r.URL.Path) {
68-
// Serve the embedded file.
68+
// Serve the embedded file
6969
distHandler.ServeHTTP(w, r)
7070
return
7171
}
72-
// Otherwise hand off to the SW via redirect.
73-
redirectToHelia(w, r)
72+
73+
// Otherwise serve the index file
74+
http.ServeFile(w, r, "dist/index.html")
75+
76+
// Otherwise hand off to the SW via redirect
77+
// redirectToHelia(w, r)
7478
}
7579

7680
// -----------------------------------------------------------------------------

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"@helia/http": "^3.0.8",
6060
"@helia/interface": "^6.0.2",
6161
"@helia/routers": "^4.0.3",
62-
"@helia/verified-fetch": "^4.0.1",
62+
"@helia/verified-fetch": "^4.0.3",
6363
"@libp2p/crypto": "^5.1.13",
6464
"@libp2p/dcutr": "^3.0.7",
6565
"@libp2p/identify": "^4.0.7",
@@ -80,6 +80,8 @@
8080
"multiformats": "^13.4.1",
8181
"react": "^19.0.0",
8282
"react-dom": "^19.0.0",
83+
"react-icons": "^5.5.0",
84+
"react-router-dom": "^7.9.5",
8385
"tachyons": "^4.12.0",
8486
"weald": "^1.1.1"
8587
},
@@ -105,8 +107,7 @@
105107
"patch-package": "^8.0.0",
106108
"playwright": "^1.45.3",
107109
"rimraf": "^6.0.1",
108-
"wait-on": "^9.0.1",
109-
"wherearewe": "^2.0.1"
110+
"wait-on": "^9.0.1"
110111
},
111112
"sideEffects": [
112113
"*.css"

playwright.config.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,14 @@ export default defineConfig({
5555
{
5656
name: 'firefox',
5757
use: {
58-
...devices['Desktop Firefox']
58+
...devices['Desktop Firefox'],
59+
launchOptions: {
60+
firefoxUserPrefs: {
61+
// if we redirect too quickly, too many times, Firefox deletes all
62+
// site application data (e.g. the service worker)
63+
'privacy.bounceTrackingProtection.mode': 0
64+
}
65+
}
5966
}
6067
},
6168
{
@@ -91,7 +98,8 @@ export default defineConfig({
9198
},
9299
launchOptions: {
93100
firefoxUserPrefs: {
94-
'dom.serviceWorkers.enabled': false
101+
'dom.serviceWorkers.enabled': false,
102+
'privacy.bounceTrackingProtection.mode': 0
95103
}
96104
},
97105
/**

public/_kubo_redirects

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
/ipns/* /ipfs-sw-first-hit.html 200
2-
/ipfs/* /ipfs-sw-first-hit.html 200
1+
# https://specs.ipfs.tech/http-gateways/web-redirects-file/
2+
# Used in the e2e test suite - different to _redirects because kubo handles 302s
3+
# and the :splat differently to cloudflare
4+
/ipns/* /index.html 200
5+
/ipfs/* /index.html 200
36
/* /index.html 200

public/_redirects

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
/ipns/* /ipfs-sw-first-hit.html/ipns/:splat 302
2-
/ipfs/* /ipfs-sw-first-hit.html/ipfs/:splat 302
1+
# https://specs.ipfs.tech/http-gateways/web-redirects-file/
2+
# https://developers.cloudflare.com/pages/configuration/redirects/
3+
/ipfs/* /index.html/:splat 302
4+
/ipns/* /index.html/:splat 302

public/index.html

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,10 @@
103103
</style>
104104
</head>
105105
<body>
106-
<div class="loading-container loading-indicator-js hidden">
106+
<div class="loading-container loading-indicator-js">
107107
<div class="loading-animation"></div>
108108
</div>
109-
<div id="root" class="sans-serif f5"></div>
110-
<script>
111-
window.addEventListener('DOMContentLoaded', () => {
112-
document.querySelector('.loading-indicator-js').classList.add('hidden')
113-
document.getElementById('root').style.display = 'block'
114-
})
115-
</script>
109+
<div id="root" class="sans-serif charcoal f5"></div>
116110
<%= JS_SCRIPT_TAG %>
117111
</body>
118112
</html>

public/ipfs-sw-first-hit.html

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/app.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,12 @@ form {
3636
.cursor-disabled {
3737
cursor: not-allowed;
3838
}
39+
40+
header a {
41+
text-decoration: none;
42+
color: var(--aqua);
43+
}
44+
45+
header a:hover {
46+
color: #EEE;
47+
}

0 commit comments

Comments
 (0)