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

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

Next.js (App Router) TypeScript

Đoạn mã TypeScript cho Next.js (App Router), 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.

Next.js (App Router) TypeScript

Cài đặt
npx create-next-app@latest
Tệp
route.ts
Chạy
npm run dev
// app/pixel.gif/route.ts
const GIF = Uint8Array.from(atob('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), (c) => c.charCodeAt(0));

export function GET() {
  return new Response(GIF, {
    headers: {
      'Content-Type': 'image/gif',
      'Content-Length': String(GIF.length),
      'Cache-Control': 'no-store',
    },
  });
}

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: Next.js (App Router)

Thêm với TypeScript