TanStack Start TypeScript
/pixel.gif へのリクエストに空の GIF を返す、TanStack Start 用の TypeScript スニペット。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