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

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

TanStack Start TypeScript

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

TanStack Start TypeScript

Cài đặt
npm create @tanstack/start@latest
Tệp
pixel.ts
Chạy
npm run dev
// src/routes/pixel[.]gif.ts  (a literal dot in a file route name is escaped as [.])
import { createFileRoute } from '@tanstack/react-router';

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

export const Route = createFileRoute('/pixel.gif')({
  server: {
    handlers: {
      GET: () =>
        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: TanStack Start

Thêm với TypeScript