emptygif
語言: 繁體中文

所有語言和框架

Hono on Deno TypeScript

適用於 Hono on Deno 的 TypeScript 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。

Hono on Deno TypeScript

安裝
deno add jsr:@hono/hono
檔案
server.ts
執行
deno run --allow-net server.ts
import { Hono } from 'jsr:@hono/hono';
import { decodeBase64 } from 'jsr:@std/encoding/base64';

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

const app = new Hono();

app.get('/pixel.gif', (c) =>
  c.body(GIF, 200, {
    'Content-Type': 'image/gif',
    'Cache-Control': 'no-store',
  }),
);

Deno.serve({ port: 8080 }, app.fetch);

我們執行了這段程式碼,並比對了它回傳的位元組。

驗證

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

官方網站: Hono on Deno

更多 TypeScript 範例