emptygif
语言: 简体中文

所有语言和框架

Hono on Bun TypeScript

一个用于 Hono on Bun 的 TypeScript 代码片段,以空 GIF 响应对 /pixel.gif 的请求,GIF 在启动时只解码一次。

Hono on Bun TypeScript

安装
bun add hono
文件
server.ts
运行
bun server.ts
import { Hono } from 'hono';

const GIF = Uint8Array.from(atob('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), (c) => c.charCodeAt(0));

const app = new Hono();

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

// Bun serves the default export: { fetch, port }.
export default { port: 8080, fetch: app.fetch };

我们运行了此代码片段,并比对了它返回的字节。

验证

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

官方网站: Hono on Bun

更多 TypeScript 示例