Netlify Edge Functions TypeScript
適用於 Netlify Edge Functions 的 TypeScript 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。
Netlify Edge Functions TypeScript
// netlify/edge-functions/pixel.ts (runs on Deno at the edge)
import type { Config } from '@netlify/edge-functions';
const GIF = Uint8Array.from(atob('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), (c) => c.charCodeAt(0));
export default () =>
new Response(GIF, {
headers: {
'Content-Type': 'image/gif',
'Content-Length': String(GIF.length),
'Cache-Control': 'no-store',
},
});
export const config: Config = { path: '/pixel.gif' };
我們執行了這段程式碼,並比對了它回傳的位元組。
驗證
curl -sI http://localhost:8080/pixel.gif