TanStack Start TypeScript
適用於 TanStack Start 的 TypeScript 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。
TanStack Start TypeScript
// src/routes/pixel[.]gif.ts (a literal dot in a file route name is escaped as [.])
import { createFileRoute } from '@tanstack/react-router';
const GIF = Uint8Array.from(atob('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), (c) => c.charCodeAt(0));
export const Route = createFileRoute('/pixel.gif')({
server: {
handlers: {
GET: () =>
new Response(GIF, {
headers: {
'Content-Type': 'image/gif',
'Content-Length': String(GIF.length),
'Cache-Control': 'no-store',
},
}),
},
},
});
我們執行了這段程式碼,並比對了它回傳的位元組。
驗證
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)
- 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