emptygif
Bahasa: Bahasa Indonesia

Semua bahasa dan framework

Deno Deploy (deno serve) TypeScript

Snippet TypeScript untuk Deno Deploy (deno serve) yang menjawab request ke /pixel.gif dengan empty GIF, yang di-decode sekali saat startup.

Deno Deploy (deno serve) TypeScript

File
main.ts
Jalankan
deno serve --port 8080 main.ts
import { decodeBase64 } from 'jsr:@std/encoding/base64';

const GIF = decodeBase64('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');

export default {
  fetch(req) {
    if (new URL(req.url).pathname !== '/pixel.gif') {
      return new Response('Not Found', { status: 404 });
    }
    return new Response(GIF, {
      headers: { 'Content-Type': 'image/gif', 'Cache-Control': 'no-store' },
    });
  },
} satisfies Deno.ServeDefaultExport;

Kami telah menjalankan snippet ini dan membandingkan byte yang dikembalikannya.

Periksa

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

Situs resmi: Deno Deploy (deno serve)

Lainnya dalam TypeScript