Skip to content

Commit

Permalink
make scramjet.init not register service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
Percslol committed Dec 30, 2024
1 parent 699f4ba commit e9ba8eb
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 21 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"build": "rspack build --mode production",
"rewriter:build": "cd rewriter/wasm/ && bash build.sh && cd ../../",
"dev": "node server.js",
"dev:debug": "DEBUG=1 node server.js",
"prepack": "RELEASE=1 npm run rewriter:build && npm run build",
"pub": "npm publish --no-git-checks --access public",
"format": "prettier --config .prettierrc.js --write .",
Expand Down
2 changes: 1 addition & 1 deletion rspack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default defineConfig({
}
})(),
}),
process.env.DEBUG === "true"
process.env.DEBUG
? new RsdoctorRspackPlugin({
supports: {
parseBundle: true,
Expand Down
12 changes: 2 additions & 10 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,8 @@ if (!process.env.CI) {
chmodSync(".git/hooks/pre-commit", 0o755);
} catch {}

const watch = spawn("pnpm", ["rspack", "-w"], {
detached: true,
spawn("pnpm", ["rspack", "-w"], {
stdio: "inherit",
cwd: process.cwd(),
});

watch.stdout.on("data", (data) => {
console.log(`${data}`);
});

watch.stderr.on("data", (data) => {
console.log(`${data}`);
});
}
3 changes: 2 additions & 1 deletion static/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const scramjet = new ScramjetController({
},
});

scramjet.init("./sw.js");
scramjet.init();
navigator.serviceWorker.register("./sw.js");

const connection = new BareMux.BareMuxConnection("/baremux/worker.js");
const flex = css`
Expand Down
10 changes: 2 additions & 8 deletions static/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@ importScripts(

const scramjet = new ScramjetServiceWorker();

async function handleRequest(event) {
self.addEventListener("fetch", async (event) => {
await scramjet.loadConfig();
if (scramjet.route(event)) {
return scramjet.fetch(event);
event.respondWith(scramjet.fetch(event));
}

return fetch(event.request);
}

self.addEventListener("fetch", (event) => {
event.respondWith(handleRequest(event));
});

let playgroundData;
Expand Down
3 changes: 2 additions & 1 deletion static/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const scramjet = new ScramjetController({
},
});

scramjet.init("./sw.js");
scramjet.init();
navigator.serviceWorker.register("./sw.js");

const connection = new BareMux.BareMuxConnection("/baremux/worker.js");
const flex = css`
Expand Down

0 comments on commit e9ba8eb

Please sign in to comment.