Skip to content

Commit 471467d

Browse files
committed
feat: 使用 loadURL 来解决对 url 和文件的获取不一致问题
1 parent 8907f30 commit 471467d

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@
2424

2525
```sh
2626
curl -fsSL https://x.deno.js.cn/install.sh | sh
27+
export DENO_INSTALL="/root/.deno"
28+
export PATH="$DENO_INSTALL/bin:$PATH"
2729
deno run -A --unstable qrcode/index.mjs
2830
```

chatroom/index.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Sono } from "jsr:@sono/core";
2+
import { loadUrl } from "../load-url/index.ts";
23
const sono = new Sono();
34
Deno.serve(
45
/**
@@ -10,7 +11,7 @@ Deno.serve(
1011
return sono.connect(req);
1112
}
1213
return new Response(
13-
await Deno.readTextFile(new URL("./client.html", import.meta.url)),
14+
await loadUrl(new URL("./client.html", import.meta.url)),
1415
{ headers: { "content-type": "text/html" } }
1516
);
1617
}

load-url/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const loadUrl = (url: URL) => {
2+
if (url.protocol === "file:") {
3+
return Deno.readFile(url);
4+
} else {
5+
return fetch(url).then((res) => res.arrayBuffer());
6+
}
7+
};

0 commit comments

Comments
 (0)