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

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

Qwik City TypeScript

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

Qwik City TypeScript

Cài đặt
npm create qwik@latest
Tệp
index.ts
Chạy
npm run dev
// src/routes/pixel.gif/index.ts - an endpoint: no default export, just onGet
import type { RequestHandler } from '@builder.io/qwik-city';

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

export const onGet: RequestHandler = ({ send }) => {
  send(
    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: Qwik City

Thêm với TypeScript