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