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

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

Astro TypeScript

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

Astro TypeScript

Cài đặt
npm create astro@latest
Tệp
pixel.ts
Chạy
npm run dev
// src/pages/pixel.gif.ts  (on-demand rendering needs a server adapter in production)
import type { APIRoute } from 'astro';

export const prerender = false;

const GIF = Uint8Array.from(atob('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), (c) => c.charCodeAt(0));

export const GET: APIRoute = () =>
  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: Astro

Thêm với TypeScript