0.2.2 • Published 5 months ago

@godsreveal/vercel-bun v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

vercel-bun

Bun runtime for Vercel serverless functions

Overview

vercel-bun is a custom Vercel runtime that enables you to run serverless functions using the Bun JavaScript runtime instead of Node.js. This runtime provides improved performance, better TypeScript support, and access to Bun's native APIs.

Features

  • 🚀 High Performance: Uses Bun's fast JavaScript runtime (version 1.2.15 by default)
  • 📦 Native TypeScript: Built-in TypeScript support without additional compilation
  • 🌐 Web Standard APIs: Uses native Request and Response interfaces
  • 🏗️ Framework Agnostic: Works with any framework that supports Bun (Elysia, Hono, etc.)
  • 🔧 Configurable: Customizable Bun version

Usage

1. Configure your vercel.json file

{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "functions": {
    "api/index.ts": {
      "runtime": "@godsreveal/vercel-bun@0.2.2"
    }
  },
  // Optional: use if you want all /api routes to be handled by /api/index.ts
  "rewrites": [{ "source": "/api/(.*)", "destination": "/api/index.ts" }]
}

2. Create a Bun serverless function

Basic Handler (Vanilla)

// api/index.ts
export default function handler(req: Request) {
  return new Response(
    JSON.stringify({ message: `Hello from bun@${Bun.version}` }),
    {
      headers: { "Content-Type": "application/json" },
    }
  );
}

Advanced Handler (with Elysia)

// api/index.ts
import { Elysia, t } from "elysia";

const app = new Elysia({ prefix: "/api" })
  .get("/", () => `Hello from bun@${Bun.version}`)
  .get("/hello", ({ query }) => `Hello ${query.firstName} ${query.lastName}`, {
    query: t.Object({
      firstName: t.String(),
      lastName: t.String(),
    }),
  })
  .post(
    "/users",
    async ({ body }) => {
      // Your logic here
      return { success: true, data: body };
    },
    {
      body: t.Object({
        name: t.String(),
        email: t.String(),
      }),
    }
  );

// Development server (runs locally with `bun run api/index.ts`)
if (process.env.NODE_ENV !== "production") {
  app.listen({ port: 3000 });
  console.log("Server is running on http://localhost:3000");
}

export default app.handle;

3. Deploy to Vercel

Deploy your GitHub repository to Vercel.

Configuration

Environment Variables

VariableDescriptionDefaultExample
BUN_VERSIONSpecify the Bun version to use1.2.151.2.15

Examples

See the example directory for a complete example of using this runtime with a Next.js project.

Live Bun Redis/S3 Client Demo

Next Steps

  • Framework Examples: Add more framework examples (grammY, Hono, Fastify, etc.).

Goals

  • First-class Vercel Integration: Native Bun runtime support in Vercel's platform for both serverless and edge functions.
  • Next.js Integration: Runtime specification in next.config.js for API routes and React Server Components.
0.2.2

5 months ago

0.2.2-alpha.1

5 months ago

0.2.1

5 months ago

0.2.1-alpha.4

5 months ago

0.2.1-alpha.3

5 months ago

0.2.1-alpha.2

5 months ago

0.2.1-alpha.1

5 months ago

0.2.0

5 months ago

0.2.0-alpha.10

5 months ago

0.2.0-alpha.9

5 months ago

0.2.0-alpha.8

5 months ago

0.2.0-alpha.7

5 months ago

0.2.0-alpha.6

5 months ago

0.2.0-alpha.5

5 months ago

0.2.0-alpha.4

5 months ago

0.2.0-alpha.3

5 months ago

0.2.0-alpha.2

5 months ago

0.2.0-alpha.1

5 months ago

0.1.2

5 months ago

0.1.1

5 months ago

0.1.0

5 months ago

0.0.51-alpha.2

5 months ago

0.0.51-alpha.1

5 months ago

0.0.50

5 months ago

0.0.49

5 months ago

0.0.48

5 months ago

0.0.47

5 months ago

0.0.46

5 months ago

0.0.45

5 months ago

0.0.44

5 months ago

0.0.43

5 months ago

0.0.42

5 months ago

0.0.41

5 months ago

0.0.40

5 months ago

0.0.39

5 months ago

0.0.38

5 months ago

0.0.37

5 months ago

0.0.36

5 months ago

0.0.35

5 months ago

0.0.34

5 months ago

0.0.33

5 months ago

0.0.32

5 months ago

0.0.31

5 months ago

0.0.30

6 months ago

0.0.29

6 months ago

0.0.28

6 months ago

0.0.27

6 months ago

0.0.26

6 months ago

0.0.25

6 months ago

0.0.24

6 months ago

0.0.23

6 months ago

0.0.22

6 months ago

0.0.21

6 months ago

0.0.20

6 months ago

0.0.19

6 months ago

0.0.18

6 months ago

0.0.17

6 months ago

0.0.16

6 months ago

0.0.15

6 months ago

0.0.14

6 months ago

0.0.13

6 months ago

0.0.12

6 months ago

0.0.11

6 months ago

0.0.10

6 months ago

0.0.9

6 months ago

0.0.8

6 months ago

0.0.7

6 months ago

0.0.6

6 months ago

0.0.5

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago