How ipfs/service-worker-gateway works
Project type and purpose
• This is a full-stack web application whose core feature is an in-browser IPFS Gateway implemented as a Service Worker.
• The frontend is a React+TypeScript SPA; the “backend” is a lightweight static‐file server (Node/TypeScript or Go) that also provides a reverse-proxy for subdomain‐style IPFS path routing.
• The Service Worker itself contains an embedded Helia IPFS node and uses the verified-fetch library to retrieve, hash-verify, and reassemble blocks from the IPFS network or configured HTTP gateways.
File structure
• Top-level scripts & config:
• build.js, serve.ts → Node scripts to bundle and serve the frontend.
• main.go → Go HTTP server for static assets + reverse proxy (subdomain routing / IPNS).
• package.json, tsconfig.json, babel.config.json → build & toolchain config.
• public/ → static HTML, SW manifests, redirect rules.
• src/
• app.tsx, components/, context/, pages/ → React SPA + UI for SW config.
• sw.ts, ipfs-sw-first-hit.ts, service-worker-utils.ts → Service Worker entrypoints & utilities.
• lib/ → helper modules (block fetching, CID verification, routing logic, local storage, SW messaging).
• tests
• test-e2e/ → Playwright E2E suites that spin up the server, register the SW, and exercise IPFS fetch flows.
• test/ → unit tests for utility functions.
• .github/workflows → CI/CD build, test, and deploy pipelines.
README for additional insights
• The README explicitly describes:
• Helia + verified-fetch inside a Service Worker.
• Goals: shift block retrieval + hash verification to the client, reduce backend load.
• How the reverse proxy enables subdomain gateway URLs.
• CI/CD workflows to build TS code, compile Go, run tests, and deploy to staging/production.