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

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

Vercel Functions TypeScript

Đoạn mã TypeScript cho Vercel 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.

Vercel Functions TypeScript

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

Chúng tôi đã biên dịch hoặc kiểm tra kiểu đoạn mã này.

Kiểm tra

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

Trang chính thức: Vercel Functions

Thêm với TypeScript