Vercel Functions TypeScript
Ein TypeScript-Snippet für Vercel Functions, das Anfragen an /pixel.gif mit dem leeren GIF beantwortet, das einmal beim Start dekodiert wird.
Vercel Functions TypeScript
// api/pixel.ts - served at /api/pixel; map /pixel.gif to it in vercel.json:
// { "rewrites": [{ "source": "/pixel.gif", "destination": "/api/pixel" }] }
// (In a Next.js project use an App Router route handler instead.)
const GIF = Uint8Array.from(atob('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), (c) => c.charCodeAt(0));
export function GET() {
return new Response(GIF, {
headers: { 'Content-Type': 'image/gif', 'Cache-Control': 'no-store' },
});
}
Wir haben dieses Snippet kompiliert oder seine Typen geprüft.
Prüfen
curl -sI http://localhost:8080/pixel.gif
Offizielle Website: Vercel Functions
Mehr in 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
- Encore.ts
- NestJS
- AdonisJS
- Cloudflare Workers
- Cloudflare Pages Functions
- Deno Deploy (deno serve)
- Netlify Functions
- Netlify Edge Functions
- Deno one-liner