emptygif
语言: 简体中文

所有语言和框架

Vercel Functions TypeScript

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

Vercel Functions TypeScript

文件
pixel.ts
运行
vercel dev
// api/pixel.ts - served at /api/pixel; map /pixel.gif to it in vercel.json:
//   { "rewrites": [{ "source": "/pixel.gif", "destination": "/api/pixel" }] }
// (In a Next.js project use an App Router route handler instead.)
const GIF = Uint8Array.from(atob('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), (c) => c.charCodeAt(0));

export function GET() {
  return new Response(GIF, {
    headers: { 'Content-Type': 'image/gif', 'Cache-Control': 'no-store' },
  });
}

我们编译或类型检查了此代码片段。

验证

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

官方网站: Vercel Functions

更多 TypeScript 示例