emptygif
言語: 日本語

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

Deno.serve TypeScript

/pixel.gif へのリクエストに空の GIF を返す、Deno.serve 用の TypeScript スニペット。GIF は起動時に一度だけデコードします。

Deno.serve TypeScript

ファイル
server.ts
実行
deno run --allow-net server.ts
import { decodeBase64 } from 'jsr:@std/encoding/base64';

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

Deno.serve({ port: 8080 }, (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' },
  });
});

このスニペットは実行し、返されたバイト列を照合しました。

確認

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

公式サイト: Deno.serve

TypeScript の他の例