emptygif
ਭਾਸ਼ਾ: ਪੰਜਾਬੀ

ਸਾਰੀਆਂ ਭਾਸ਼ਾਵਾਂ ਅਤੇ ਫਰੇਮਵਰਕ

NestJS TypeScript

NestJS ਲਈ TypeScript ਸਨਿੱਪਟ, ਜੋ /pixel.gif ਦੀਆਂ ਬੇਨਤੀਆਂ ਦਾ ਜਵਾਬ ਖਾਲੀ GIF ਨਾਲ ਦਿੰਦਾ ਹੈ; GIF ਸ਼ੁਰੂਆਤ ’ਤੇ ਇੱਕ ਵਾਰ ਡੀਕੋਡ ਹੁੰਦੀ ਹੈ।

NestJS TypeScript

ਇੰਸਟਾਲ
npm i @nestjs/core @nestjs/common @nestjs/platform-express reflect-metadata rxjs
ਫਾਈਲ
main.ts
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();

ਅਸੀਂ ਇਹ ਸਨਿੱਪਟ ਚਲਾਇਆ ਅਤੇ ਇਸ ਵੱਲੋਂ ਵਾਪਸ ਕੀਤੀਆਂ ਬਾਈਟਾਂ ਦੀ ਤੁਲਨਾ ਕੀਤੀ।

ਜਾਂਚੋ

curl -sI http://localhost:8080/pixel.gif

ਅਧਿਕਾਰਤ ਸਾਈਟ: NestJS

TypeScript ਵਿੱਚ ਹੋਰ