emptygif
Harshe: Hausa

Duk harsuna da frameworks

Bun.serve TypeScript

Snippet na TypeScript don Bun.serve da ke amsa requests zuwa /pixel.gif da empty GIF, wanda ake decoding ɗinsa sau ɗaya lokacin farawa.

Bun.serve TypeScript

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

Mun gudanar da wannan snippet kuma mun kwatanta bytes ɗin da ya mayar.

Duba shi

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

Shafin hukuma: Bun.serve

Ƙari a TypeScript