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

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

SvelteKit TypeScript

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

SvelteKit TypeScript

Cài đặt
npx sv create
Tệp
+server.ts
Chạy
npm run dev
// src/routes/pixel.gif/+server.ts
import type { RequestHandler } from './$types';

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

export const GET: RequestHandler = () =>
  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: SvelteKit

Thêm với TypeScript