Deno.serve TypeScript
Snippet na TypeScript don Deno.serve da ke amsa requests zuwa /pixel.gif da empty GIF, wanda ake decoding ɗinsa sau ɗaya lokacin farawa.
Deno.serve TypeScript
import { decodeBase64 } from 'jsr:@std/encoding/base64';
const GIF = decodeBase64('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
Deno.serve({ port: 8080 }, (req) => {
if (new URL(req.url).pathname !== '/pixel.gif') {
return new Response('Not Found', { status: 404 });
}
return new Response(GIF, {
headers: { 'Content-Type': 'image/gif', 'Cache-Control': 'no-store' },
});
});
Mun gudanar da wannan snippet kuma mun kwatanta bytes ɗin da ya mayar.
Duba shi
curl -sI http://localhost:8080/pixel.gif
Ƙari a TypeScript
- Next.js (App Router)
- Hono
- Bun.serve
- Elysia
- SvelteKit
- Nuxt (Nitro server route)
- Astro
- React Router (framework mode, ex-Remix)
- TanStack Start
- SolidStart
- Fresh
- Oak
- Encore.ts
- NestJS
- AdonisJS
- Cloudflare Workers
- Cloudflare Pages Functions
- Deno Deploy (deno serve)
- Vercel Functions
- Netlify Functions
- Netlify Edge Functions
- Deno one-liner