Skip to content

Commit

Permalink
feat: add Bun runtime using TypeScript (TechEmpower#8416)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcbarbosa authored Sep 19, 2023
1 parent b53c073 commit 42aecae
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
22 changes: 22 additions & 0 deletions frameworks/TypeScript/bun/README.md
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 0 deletions frameworks/TypeScript/bun/benchmark_config.json
Original file line number Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions frameworks/TypeScript/bun/bun.dockerfile
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions frameworks/TypeScript/bun/config.toml
Original file line number Diff line number Diff line change
@@ -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 changes: 21 additions & 0 deletions frameworks/TypeScript/bun/src/index.ts
Original file line number Diff line number Diff line change
@@ -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}`);

0 comments on commit 42aecae

Please sign in to comment.