emptygif
Ngôn ngữ: Tiếng Việt

Tất cả ngôn ngữ và framework

Netlify Edge Functions TypeScript

Đoạn mã TypeScript cho Netlify Edge Functions, trả lời các yêu cầu tới /pixel.gif bằng GIF rỗng, được giải mã một lần khi khởi động.

Netlify Edge Functions TypeScript

Tệp
pixel.ts
Chạy
netlify dev
// 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' };

Chúng tôi đã chạy đoạn mã này và so sánh các byte nó trả về.

Kiểm tra

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

Trang chính thức: Netlify Edge Functions

Thêm với TypeScript