bun mini server

卓能文發表於2024-07-21

server.ts:

import { serve } from "bun";

const id = Math.random().toString(36).slice(2);

serve({
    port: process.env.PORT || 8080,
    development: false,

    // Share the same port across multiple processes
    // This is the important part!
    reusePort: true,

    async fetch(request) {
        return new Response("Hello from Bun #" + id + "!\n");
    }
});

執行:

bun run server.ts

相關文章