Bun.serve TypeScript
一个用于 Bun.serve 的 TypeScript 代码片段,以空 GIF 响应对 /pixel.gif 的请求,GIF 在启动时只解码一次。
Bun.serve TypeScript
const GIF = Buffer.from('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==', 'base64');
Bun.serve({
port: 8080,
routes: {
// A static Response is built once and served for every request.
'/pixel.gif': new Response(GIF, {
headers: { 'Content-Type': 'image/gif', 'Cache-Control': 'no-store' },
}),
},
});
我们运行了此代码片段,并比对了它返回的字节。
验证
curl -sI http://localhost:8080/pixel.gif
更多 TypeScript 示例
- Next.js (App Router)
- Hono
- Elysia
- Deno.serve
- SvelteKit
- Nuxt (Nitro server route)
- Astro
- React Router (framework mode, ex-Remix)
- TanStack Start
- SolidStart
- Hono on Bun
- Hono on Deno
- srvx (universal fetch server)
- Qwik City
- RedwoodSDK
- Angular SSR (Express server.ts)
- Fresh
- Oak
- Encore.ts
- NestJS
- AdonisJS
- Cloudflare Workers
- Cloudflare Pages Functions
- Deno Deploy (deno serve)
- Vercel Functions
- Netlify Functions
- Netlify Edge Functions
- Deno one-liner