Quellcode durchsuchen

upgrade Deno to v1.42.1 (#8842)

* upgrade Deno to v1.41.2

* Update deno.dockerfile
Divy Srivastava vor 1 Jahr
Ursprung
Commit
57e4811262

+ 2 - 2
frameworks/TypeScript/deno/deno.dockerfile

@@ -1,4 +1,4 @@
-FROM denoland/deno:1.36.4
+FROM denoland/deno:1.42.1
 
 EXPOSE 8080
 
@@ -12,4 +12,4 @@ RUN deno cache main.ts
 
 EXPOSE 8080
 
-CMD ["run", "--allow-net", "--unstable", "main.ts"]
+CMD ["run", "-A", "--unstable-net", "spawn.ts"]

+ 10 - 17
frameworks/TypeScript/deno/src/main.ts

@@ -1,24 +1,17 @@
-const options = {
-  // Date and Content-Type headers are automatically set.
-  headers: {
-    "Server": "Deno",
-  },
-};
-
-type HandlerFn = (req: Request) => Promise<Response> | Response;
-
-const handlers: Record<string, HandlerFn> = {
-  "/json": () => Response.json({ message: "Hello, World!" }, options),
-  "/plaintext": () => new Response("Hello, World!", options),
-};
+const HELLO_WORLD_STR = "Hello, World!";
+const options: ResponseInit = { headers: { "Server": "Deno" } };
 
 Deno.serve({
+  reusePort: true,
   handler: (req: Request) => {
     const path = req.url.slice(req.url.indexOf("/", 8));
-    const fn = handlers[path];
-    return fn
-      ? fn(req)
-      : new Response("404 Not Found", { status: 404, ...options });
+    if (path == "/plaintext") {
+      return new Response(HELLO_WORLD_STR, options);
+    } else if (path == "/json") {
+      return Response.json({ message: HELLO_WORLD_STR }, options);
+    } else {
+      return new Response("404 Not Found", { status: 404, ...options });
+    }
   },
   onError(err) {
     console.error(err);

+ 13 - 0
frameworks/TypeScript/deno/src/spawn.ts

@@ -0,0 +1,13 @@
+import os from "node:os";
+import process from "node:process";
+
+const numCPUs = os.cpus().length;
+for (let i = 0; i < numCPUs; i++) {
+  new Deno.Command(Deno.execPath(), {
+    args: ["run", "-A", "--unstable-net", "main.ts"],
+    stdin: "inherit",
+    stdout: "inherit",
+    stderr: "inherit",
+    env: { ...process.env },
+  }).spawn();
+}