Skip to content

Commit 4fa9b1b

Browse files
committed
demo: configure wasm-demo for mainnet and add bun dev server
Point the bootnode at /dnsaddr/mainnet.ethswarm.org (resolved in-browser via DoH), set network-id=1/--mainnet=true, fresh data-dir. Add serve.js (Bun static server with application/wasm MIME and root SW scope).
1 parent 8667a8a commit 4fa9b1b

2 files changed

Lines changed: 52 additions & 5 deletions

File tree

wasm-demo/serve.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { file } from "bun";
2+
import { extname, join, normalize } from "path";
3+
4+
const ROOT = import.meta.dir;
5+
const PORT = Number(process.env.PORT ?? 8080);
6+
7+
const MIME = {
8+
".html": "text/html; charset=utf-8",
9+
".js": "text/javascript; charset=utf-8",
10+
".mjs": "text/javascript; charset=utf-8",
11+
".css": "text/css; charset=utf-8",
12+
".json": "application/json; charset=utf-8",
13+
".wasm": "application/wasm",
14+
".map": "application/json",
15+
};
16+
17+
Bun.serve({
18+
port: PORT,
19+
idleTimeout: 0,
20+
async fetch(req) {
21+
let { pathname } = new URL(req.url);
22+
if (pathname === "/") pathname = "/index.html";
23+
24+
// Resolve within ROOT and guard against path traversal.
25+
const safe = normalize(pathname).replace(/^(\.\.(\/|\\|$))+/, "");
26+
const path = join(ROOT, safe);
27+
const f = file(path);
28+
if (!(await f.exists())) {
29+
return new Response("Not found", { status: 404 });
30+
}
31+
32+
const type = MIME[extname(path).toLowerCase()] || "application/octet-stream";
33+
return new Response(f, {
34+
headers: {
35+
"Content-Type": type,
36+
// Allow the service worker (served at /sw_bundle.js) to claim root scope.
37+
"Service-Worker-Allowed": "/",
38+
"Cache-Control": "no-cache",
39+
},
40+
});
41+
},
42+
});
43+
44+
console.log(`bee wasm demo: http://localhost:${PORT}`);

wasm-demo/sw.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,19 @@ async function main() {
108108
"start",
109109
"--password",
110110
"testing",
111+
// Mainnet bootnodes. The dnsaddr is resolved in-browser via DoH
112+
// (pkg/p2p/discover_js.go), yielding the libp2p.direct AutoTLS secure
113+
// WebSocket addresses that the wasmws transport can dial.
111114
"--bootnode",
112-
"/ip4/49.12.172.37/tcp/32510/tls/sni/49-12-172-37.k2k4r8mh36hk5mcrg2syh2amdbl4dmd08fjhtqrtvyn0gef71auumrvf.libp2p.direct/ws/p2p/QmWbXocGMpfa8zApx9kCNwfmc35bbRJv136bdtuQjbR4wL",
115+
"/dnsaddr/mainnet.ethswarm.org",
113116
"--data-dir",
114-
"/home/user/.bee/sepolia",
117+
"/home/user/.bee/mainnet",
115118
"--verbosity",
116119
"debug",
117120
// '--blockchain-rpc-endpoint',
118-
// 'https://ethereum-sepolia-rpc.publicnode.com/ac5b7f52aabd778861c2588f872f15c5fc34f0b343ec3d18ac2e91f5526e9c2b',
119-
"--mainnet=false",
120-
"--network-id=5",
121+
// 'https://rpc.gnosischain.com',
122+
"--mainnet=true",
123+
"--network-id=1",
121124
"--p2p-ws-enable",
122125
];
123126

0 commit comments

Comments
 (0)