emptygif
اللغة: العربية

كل اللغات وأطر العمل

Astro TypeScript

مقتطف بلغة TypeScript لـ Astro يستجيب لطلبات /pixel.gif بملف GIF الفارغ، الذي يُفك ترميزه مرة واحدة عند بدء التشغيل.

Astro TypeScript

التثبيت
npm create astro@latest
الملف
pixel.ts
التشغيل
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',
    },
  });

شغّلنا هذا المقتطف وقارنّا البايتات التي أعادها.

التحقق

curl -sI http://localhost:8080/pixel.gif

الموقع الرسمي: Astro

المزيد بلغة TypeScript