Browse Source

feat: add Bun runtime using TypeScript (#8416)

Marcelo Barbosa 1 year ago
parent
commit
42aecaef53

+ 22 - 0
frameworks/TypeScript/bun/README.md

@@ -0,0 +1,22 @@
+# [Bun](https://bun.sh/) - A fast all-in-one JavaScript runtime
+
+## Description
+
+Bun is an all-in-one toolkit for JavaScript and TypeScript apps. It ships as a single executable
+called `bun`​.
+
+At its core is the Bun runtime, a fast JavaScript runtime designed as a drop-in replacement for
+Node.js. It's written in Zig and powered by JavaScriptCore under the hood, dramatically reducing
+startup times and memory usage.
+
+- [Bun Docs](https://bun.sh/docs)
+
+## Test URLs
+
+### Test 1: JSON Encoding
+
+    http://localhost:8080/json
+
+### Test 2: Plaintext
+
+    http://localhost:8080/plaintext

+ 20 - 0
frameworks/TypeScript/bun/benchmark_config.json

@@ -0,0 +1,20 @@
+{
+  "framework": "bun",
+  "tests": [{
+    "default": {
+      "json_url": "/json",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Platform",
+      "language": "TypeScript",
+      "flavor": "bun",
+      "platform": "bun",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "bun",
+      "versus": "nodejs"
+    }
+  }]
+}

+ 13 - 0
frameworks/TypeScript/bun/bun.dockerfile

@@ -0,0 +1,13 @@
+FROM oven/bun:1.0
+
+EXPOSE 8080
+
+WORKDIR /app
+
+USER bun
+
+COPY ./src .
+
+ENV NODE_ENV=production
+
+CMD ["bun", "index.ts"]

+ 15 - 0
frameworks/TypeScript/bun/config.toml

@@ -0,0 +1,15 @@
+[framework]
+name = "bun"
+
+[main]
+urls.plaintext = "/plaintext"
+urls.json = "/json"
+approach = "Realistic"
+classification = "Platform"
+database_os = "Linux"
+database = "None"
+os = "Linux"
+orm = "Raw"
+platform = "bun"
+webserver = "None"
+versus = "nodejs"

+ 21 - 0
frameworks/TypeScript/bun/src/index.ts

@@ -0,0 +1,21 @@
+const HELLO_WORLD_STR = "Hello, World!";
+const options: ResponseInit = { headers: { "Server": "Bun" } };
+
+const server = Bun.serve({
+  port: 8080,
+  fetch(req: Request) {
+    const { pathname } = new URL(req.url);
+
+    if (pathname === "/json") {
+      return Response.json({ message: HELLO_WORLD_STR }, options);
+    }
+
+    if (pathname === "/plaintext") {
+      return new Response(HELLO_WORLD_STR, options);
+    }
+
+    return new Response("", { status: 404 })
+  },
+});
+
+console.log(`Listening on localhost:${server.port}`);