From 42aecaef530c066d22978de3158a4a4b1ef56e5c Mon Sep 17 00:00:00 2001 From: Marcelo Barbosa Date: Tue, 19 Sep 2023 17:01:52 -0300 Subject: [PATCH] feat: add Bun runtime using TypeScript (#8416) --- frameworks/TypeScript/bun/README.md | 22 +++++++++++++++++++ .../TypeScript/bun/benchmark_config.json | 20 +++++++++++++++++ frameworks/TypeScript/bun/bun.dockerfile | 13 +++++++++++ frameworks/TypeScript/bun/config.toml | 15 +++++++++++++ frameworks/TypeScript/bun/src/index.ts | 21 ++++++++++++++++++ 5 files changed, 91 insertions(+) create mode 100644 frameworks/TypeScript/bun/README.md create mode 100644 frameworks/TypeScript/bun/benchmark_config.json create mode 100644 frameworks/TypeScript/bun/bun.dockerfile create mode 100644 frameworks/TypeScript/bun/config.toml create mode 100644 frameworks/TypeScript/bun/src/index.ts diff --git a/frameworks/TypeScript/bun/README.md b/frameworks/TypeScript/bun/README.md new file mode 100644 index 00000000000..2bf901cd406 --- /dev/null +++ b/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 diff --git a/frameworks/TypeScript/bun/benchmark_config.json b/frameworks/TypeScript/bun/benchmark_config.json new file mode 100644 index 00000000000..d4c85cadc84 --- /dev/null +++ b/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" + } + }] +} diff --git a/frameworks/TypeScript/bun/bun.dockerfile b/frameworks/TypeScript/bun/bun.dockerfile new file mode 100644 index 00000000000..0814762abe3 --- /dev/null +++ b/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"] diff --git a/frameworks/TypeScript/bun/config.toml b/frameworks/TypeScript/bun/config.toml new file mode 100644 index 00000000000..6d2201c788f --- /dev/null +++ b/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" diff --git a/frameworks/TypeScript/bun/src/index.ts b/frameworks/TypeScript/bun/src/index.ts new file mode 100644 index 00000000000..be38493ff73 --- /dev/null +++ b/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}`);