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 範例