emptygif
語言: 繁體中文

所有語言和框架

Bun.serve TypeScript

適用於 Bun.serve 的 TypeScript 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。

Bun.serve TypeScript

檔案
server.ts
執行
bun server.ts
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

官方網站: Bun.serve

更多 TypeScript 範例