NestJS TypeScript
Snippet TypeScript kanggo NestJS sing mangsuli request menyang /pixel.gif nganggo empty GIF, sing didekode sepisan nalika startup.
NestJS TypeScript
import { Controller, Get, Header, Module, StreamableFile } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
const GIF = Buffer.from('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==', 'base64');
@Controller()
class PixelController {
@Get('/pixel.gif')
@Header('Cache-Control', 'no-store')
pixel(): StreamableFile {
// A plain Buffer would be serialised as JSON; StreamableFile sends raw bytes.
return new StreamableFile(GIF, { type: 'image/gif', length: GIF.length });
}
}
@Module({ controllers: [PixelController] })
class AppModule {}
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(8080);
}
bootstrap();
Snippet iki wis dilakokake lan byte asile wis dibandhingake.
Priksa
curl -sI http://localhost:8080/pixel.gif
Liyane ing 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
- AdonisJS
- Cloudflare Workers
- Cloudflare Pages Functions
- Deno Deploy (deno serve)
- Vercel Functions
- Netlify Functions
- Netlify Edge Functions
- Deno one-liner