emptygif
言語: 日本語

すべての言語・フレームワーク

Bun.serve TypeScript

/pixel.gif へのリクエストに空の GIF を返す、Bun.serve 用の TypeScript スニペット。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 の他の例