emptygif
ภาษา: ไทย

ภาษาและเฟรมเวิร์กทั้งหมด

Vercel Functions TypeScript

ตัวอย่างโค้ด TypeScript สำหรับ Vercel Functions ที่ตอบคำขอไปยัง /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