Encore.ts TypeScript
مقتطف بلغة TypeScript لـ Encore.ts يستجيب لطلبات /pixel.gif بملف GIF الفارغ، الذي يُفك ترميزه مرة واحدة عند بدء التشغيل.
Encore.ts TypeScript
// pixel/pixel.ts (inside a service directory with an encore.service.ts)
import { api } from 'encore.dev/api';
const GIF = Buffer.from('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==', 'base64');
// A raw endpoint gets Node's req/res, so the bytes are written untouched.
export const pixel = api.raw(
{ expose: true, method: 'GET', path: '/pixel.gif' },
async (req, resp) => {
resp.writeHead(200, {
'Content-Type': 'image/gif',
'Content-Length': GIF.length,
'Cache-Control': 'no-store',
});
resp.end(GIF);
},
);
رُوجع مقابل التوثيق الحالي لإطار العمل.
التحقق
curl -sI http://localhost:8080/pixel.gif
المزيد بلغة TypeScript
- Next.js (App Router)
- Hono
- Bun.serve
- Elysia
- Deno.serve
- SvelteKit
- Nuxt (Nitro server route)
- Astro
- React Router (framework mode, ex-Remix)
- TanStack Start
- SolidStart
- Fresh
- Oak
- NestJS
- AdonisJS
- Cloudflare Workers
- Cloudflare Pages Functions
- Deno Deploy (deno serve)
- Vercel Functions
- Netlify Functions
- Netlify Edge Functions
- Deno one-liner