Skip to content

Commit 57e4811

Browse files
authored
upgrade Deno to v1.42.1 (#8842)
* upgrade Deno to v1.41.2 * Update deno.dockerfile
1 parent d71b70a commit 57e4811

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

frameworks/TypeScript/deno/deno.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM denoland/deno:1.36.4
1+
FROM denoland/deno:1.42.1
22

33
EXPOSE 8080
44

@@ -12,4 +12,4 @@ RUN deno cache main.ts
1212

1313
EXPOSE 8080
1414

15-
CMD ["run", "--allow-net", "--unstable", "main.ts"]
15+
CMD ["run", "-A", "--unstable-net", "spawn.ts"]

frameworks/TypeScript/deno/src/main.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
1-
const options = {
2-
// Date and Content-Type headers are automatically set.
3-
headers: {
4-
"Server": "Deno",
5-
},
6-
};
7-
8-
type HandlerFn = (req: Request) => Promise<Response> | Response;
9-
10-
const handlers: Record<string, HandlerFn> = {
11-
"/json": () => Response.json({ message: "Hello, World!" }, options),
12-
"/plaintext": () => new Response("Hello, World!", options),
13-
};
1+
const HELLO_WORLD_STR = "Hello, World!";
2+
const options: ResponseInit = { headers: { "Server": "Deno" } };
143

154
Deno.serve({
5+
reusePort: true,
166
handler: (req: Request) => {
177
const path = req.url.slice(req.url.indexOf("/", 8));
18-
const fn = handlers[path];
19-
return fn
20-
? fn(req)
21-
: new Response("404 Not Found", { status: 404, ...options });
8+
if (path == "/plaintext") {
9+
return new Response(HELLO_WORLD_STR, options);
10+
} else if (path == "/json") {
11+
return Response.json({ message: HELLO_WORLD_STR }, options);
12+
} else {
13+
return new Response("404 Not Found", { status: 404, ...options });
14+
}
2215
},
2316
onError(err) {
2417
console.error(err);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import os from "node:os";
2+
import process from "node:process";
3+
4+
const numCPUs = os.cpus().length;
5+
for (let i = 0; i < numCPUs; i++) {
6+
new Deno.Command(Deno.execPath(), {
7+
args: ["run", "-A", "--unstable-net", "main.ts"],
8+
stdin: "inherit",
9+
stdout: "inherit",
10+
stderr: "inherit",
11+
env: { ...process.env },
12+
}).spawn();
13+
}

0 commit comments

Comments
 (0)