Skip to content

Commit 49fe12d

Browse files
authored
feat: npm start boots up fully operational sw-gateway (#670)
* test: fix test setup * test: playwright setup is all done in global-setup * chore: fix lint * chore: fix depcheck and cleanup code * chore: re-enable ipns.record fixture loading * chore: attempt to debug CI failure with ipns record loading * chore: more ipns record loading debugging * fix: serve.ts and playwright global setup are normalized * chore: remove serve.js from prod ignore aegir * chore: remove unused imports * chore: fix dep-check
1 parent 392b4f4 commit 49fe12d

13 files changed

+613
-933
lines changed

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,25 @@ The main goals of this project are:
8181

8282
You can build and run the project locally:
8383

84-
8584
```console
8685
> npm ci
8786
> npm start
8887
```
8988

90-
Now open your browser at `http://sw.localhost:3000`
89+
Now open your browser and go to `http://localhost:3333`
90+
91+
Below is an explanation of the different URLs and what they do:
92+
93+
With reverse-proxy:
94+
* `http://localhost:3333` - The service worker gateway front-end served directly with esbuild. (localhost:3333 -> localhost:8345)
95+
* `http://localhost:3334` - The service worker gateway front-end hosted by an IPFS gateway running on 'localhost:8088'. (localhost:3334 -> localhost:8088 with x-forwarded-host header)
96+
97+
Without reverse-proxy:
98+
* `http://localhost:8345` - The service worker gateway front-end served directly with esbuild.
99+
100+
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>/`
91101

92-
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)).
102+
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)).
93103

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

docs/DEVELOPMENT.md

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,26 @@ Make sure you have installed all of the following prerequisites on your developm
1919
> npm start
2020
```
2121

22-
Now open your browser at `http://sw.localhost:3000`
22+
Now open your browser at `http://localhost:3333`
2323

24+
If you are editing code actively and wanting to see the changes, you will want to use the `3333` port because the IPFS hosted content is generated at build time and the x-forwarded-host header and stubbed DNSLink of `ipfs-host.local` will still be pointing to the old content.
2425

2526
### Enabling subdomains
2627

27-
You can enable support for subdomains with a simple nginx configuration:
28+
Subdomains are enabled by default when you run `npm start`. You will want to access the service worker gateway via a reverse proxy that ensures subdomain support:
2829

29-
```nginx
30-
# simple proxy from sw.localhost to localhost:3000
31-
server {
32-
listen 80;
30+
* `http://localhost:3333`
31+
* `http://localhost:3334`
3332

34-
server_name ~^(?<subdomain>.+)\.ipfs\.sw.localhost$ ~^(?<subdomain>.+)\.ipns\.sw.localhost$ .sw.localhost;
3533

36-
location / {
37-
proxy_pass http://localhost:3000;
38-
proxy_set_header Host $host;
39-
proxy_set_header X-Forwarded-For $remote_addr;
40-
}
41-
}
42-
```
34+
### Testing without subdomains
4335

44-
You can then run `npm start`, start your nginx server, and then visit <http://specs-ipfs-tech.ipns.sw.localhost> in your browser to load the `specs.ipfs.tech` website via Helia-based verified-fetch library, completely from the Service Worker.
36+
Unless you have some other reverse proxy setup, you can access a path-only gateway by accessing:
4537

46-
You can also try <http://sw.localhost/ipns/specs.ipfs.tech> to automatically be redirected to <http://specs-ipfs-tech.ipns.sw.localhost>. If you are not redirected, your reverse proxy may not be set up correctly.
38+
* `http://localhost:8345`
39+
* `http://127.0.0.1:8345`
40+
* `http://127.0.0.1:3333`
41+
* `http://127.0.0.1:3334`
4742

4843
## Demo links
4944

@@ -52,32 +47,32 @@ You can also try <http://sw.localhost/ipns/specs.ipfs.tech> to automatically be
5247
You have to visit the landing page first, and make sure the SW is loaded. Once it is, the below links should work for you.
5348

5449
Notes:
55-
- ⚠️ Deployment of this service worker on environments that don't enable subdomain pathing is not recommended. Path-only gateways do not provide [Origin isolation](https://docs.ipfs.tech/how-to/address-ipfs-on-web/#subdomain-gateway). NEVER use path-only gateways for loading dapps with sensitive information such as keys, passwords, wallets.
50+
- ⚠️ Deployment of this service worker on environments that don't enable subdomain pathing is not recommended. Path-only gateways do not provide [Origin isolation](https://docs.ipfs.tech/how-to/address-ipfs-on-web/#subdomain-gateway). NEVER use path-only gateways for loading dapps with sensitive information such as keys, passwords, wallets.
5651
* Attempting a few refreshes, clearing site data (cache/cookies/sw/indexDb/etc..), etc, may resolve your problem (though may be indicative of issues you can fix with a PR!)
5752
* Some content-types are not *previewable* with certain browsers. If you receive a download prompt you didn't expect: double check the returned content-type and make sure your browser supports previewing that content-type.
5853

5954
### Links
6055

6156
#### Static website and it's nested content
6257

63-
* ipfs.tech/images directory listing page - http://sw.localhost:3000/ipfs/QmeUdoMyahuQUPHS2odrZEL6yk2HnNfBJ147BeLXsZuqLJ/images
64-
* ipfs.tech/images/images/ipfs-desktop-hex.png - http://sw.localhost:3000/ipfs/QmeUdoMyahuQUPHS2odrZEL6yk2HnNfBJ147BeLXsZuqLJ/images/ipfs-desktop-hex.png
65-
* ipfs.tech website - http://sw.localhost:3000/ipfs/QmeUdoMyahuQUPHS2odrZEL6yk2HnNfBJ147BeLXsZuqLJ
58+
* ipfs.tech/images directory listing page - http://localhost:3333/ipfs/QmeUdoMyahuQUPHS2odrZEL6yk2HnNfBJ147BeLXsZuqLJ/images
59+
* ipfs.tech/images/images/ipfs-desktop-hex.png - http://localhost:3333/ipfs/QmeUdoMyahuQUPHS2odrZEL6yk2HnNfBJ147BeLXsZuqLJ/images/ipfs-desktop-hex.png
60+
* ipfs.tech website - http://localhost:3333/ipfs/QmeUdoMyahuQUPHS2odrZEL6yk2HnNfBJ147BeLXsZuqLJ
6661

6762
#### Single images
6863

69-
* router image - http://sw.localhost:3000/ipfs/bafkreicafxt3zr4cshf7qteztjzl62ouxqrofu647e44wt7s2iaqjn7bra
70-
* web3.storage logo - http://sw.localhost:3000/ipfs/bafkreif4ufrfpfcmqn5ltjvmeisgv4k7ykqz2mjygpngtwt4bijxosidqa
64+
* router image - http://localhost:3333/ipfs/bafkreicafxt3zr4cshf7qteztjzl62ouxqrofu647e44wt7s2iaqjn7bra
65+
* web3.storage logo - http://localhost:3333/ipfs/bafkreif4ufrfpfcmqn5ltjvmeisgv4k7ykqz2mjygpngtwt4bijxosidqa
7166

7267
#### Videos
7368

74-
* skateboarder stock video - http://sw.localhost:3000/ipfs/bafkreiezuss4xkt5gu256vjccx7vocoksxk77vwmdrpwoumfbbxcy2zowq
75-
* big buck bunny video - http://sw.localhost:3000/ipfs/bafybeidsp6fva53dexzjycntiucts57ftecajcn5omzfgjx57pqfy3kwbq
69+
* skateboarder stock video - http://localhost:3333/ipfs/bafkreiezuss4xkt5gu256vjccx7vocoksxk77vwmdrpwoumfbbxcy2zowq
70+
* big buck bunny video - http://localhost:3333/ipfs/bafybeidsp6fva53dexzjycntiucts57ftecajcn5omzfgjx57pqfy3kwbq
7671

7772
#### IPNS paths
7873

79-
* /ipns/libp2p.io - http://sw.localhost:3000/ipns/libp2p.io
80-
* /ipns/ipfs.tech - http://sw.localhost:3000/ipns/ipfs.tech
74+
* /ipns/libp2p.io - http://localhost:3333/ipns/libp2p.io
75+
* /ipns/ipfs.tech - http://localhost:3333/ipns/ipfs.tech
8176

8277
#### DNSLink paths
8378

0 commit comments

Comments
 (0)