emptygif
Bahasa: Bahasa Indonesia

Semua bahasa dan framework

Bun.serve TypeScript

Snippet TypeScript untuk Bun.serve yang menjawab request ke /pixel.gif dengan empty GIF, yang di-decode sekali saat startup.

Bun.serve TypeScript

File
server.ts
Jalankan
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' },
    }),
  },
});

Kami telah menjalankan snippet ini dan membandingkan byte yang dikembalikannya.

Periksa

curl -sI http://localhost:8080/pixel.gif

Situs resmi: Bun.serve

Lainnya dalam TypeScript