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

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

Deno.serve TypeScript

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

Deno.serve TypeScript

ਫਾਈਲ
server.ts
ਚਲਾਓ
deno run --allow-net server.ts
import { decodeBase64 } from 'jsr:@std/encoding/base64';

const GIF = decodeBase64('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');

Deno.serve({ port: 8080 }, (req) => {
  if (new URL(req.url).pathname !== '/pixel.gif') {
    return new Response('Not Found', { status: 404 });
  }
  return new Response(GIF, {
    headers: { 'Content-Type': 'image/gif', 'Cache-Control': 'no-store' },
  });
});

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

ਜਾਂਚੋ

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

ਅਧਿਕਾਰਤ ਸਾਈਟ: Deno.serve

TypeScript ਵਿੱਚ ਹੋਰ