Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add web-to-node-handler-abort-signal #9

Merged
merged 13 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions web-to-node-handler-abort-signal/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
8 changes: 8 additions & 0 deletions web-to-node-handler-abort-signal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
https://github.com/remix-run/remix/issues/9438

```sh
SERVER_ENTRY=/src/hono pnpm dev
SERVER_ENTRY=/src/hattip pnpm dev
SERVER_ENTRY=/src/h3 pnpm dev
SERVER_ENTRY=/src/mine pnpm dev
```
36 changes: 36 additions & 0 deletions web-to-node-handler-abort-signal/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, height=device-height, initial-scale=1.0"
/>
</head>
<body>
<button id="fetch">fetch stream</button>
<button id="abort">abort stream</button>
<pre id="response"></pre>

<script type="module">
const $ = document.querySelector.bind(document);
let abortController;

// https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort#examples
$("#fetch").addEventListener("click", async () => {
$("#response").textContent = "";
abortController = new AbortController();
const res = await fetch("/api/stream", { signal: abortController.signal });
await res.body?.pipeThrough(new TextDecoderStream()).pipeTo(new WritableStream({
write(chunk) {
$("#response").textContent += chunk;
}
}))
});

$("#abort").addEventListener("click", () => {
abortController?.abort();
});
</script>
</body>
</html>
19 changes: 19 additions & 0 deletions web-to-node-handler-abort-signal/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"lint": "biome check --apply --linter-enabled=false ."
},
"dependencies": {
"@hattip/adapter-node": "^0.0.45",
"@hiogawa/utils-node": "0.0.1-pre.17",
"@hono/node-server": "^1.11.1",
"h3": "^1.11.1",
"vite": "^5.2.11"
},
"devDependencies": {
"@types/node": "^20.12.12"
},
"packageManager": "pnpm@8.15.8+sha512.d1a029e1a447ad90bc96cd58b0fad486d2993d531856396f7babf2d83eb1823bb83c5a3d0fc18f675b2d10321d49eb161fece36fe8134aa5823ecd215feed392"
}
Loading