bun mini server

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
posted @ 2024-07-21 08:28  卓能文  阅读(2)  评论(0编辑  收藏  举报