Lahat ng language at framework
Netlify Functions TypeScript
Isang TypeScript snippet para sa Netlify Functions na sumasagot sa mga request sa /pixel.gif gamit ang empty GIF, na isang beses lang dine-decode sa startup.
Netlify Functions TypeScript
// netlify/functions/pixel.mts
import type { Config } from '@netlify/functions';
const GIF = Uint8Array.from(atob('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), (c) => c.charCodeAt(0));
export default () =>
new Response(GIF, {
headers: {
'Content-Type': 'image/gif',
'Content-Length': String(GIF.length),
'Cache-Control': 'no-store',
},
});
export const config: Config = { path: '/pixel.gif' };
Pinatakbo namin ang snippet na ito at ikinumpara ang mga byte na ibinalik nito.
Suriin
curl -sI http://localhost:8080/pixel.gif
Opisyal na site: Netlify Functions
Iba pa sa 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)
- Vercel Functions
- Netlify Edge Functions
- Deno one-liner