emptygif
भाषा: मराठी

सर्व भाषा आणि फ्रेमवर्क

Encore.ts TypeScript

Encore.ts साठी TypeScript स्निपेट, जो /pixel.gif वरच्या रिक्वेस्टना empty GIF ने उत्तर देतो. GIF स्टार्टअपला एकदाच डिकोड होतो.

Encore.ts TypeScript

इन्स्टॉल
encore app create --example=ts/hello-world
फाइल
pixel.ts
चालवा
encore run
// pixel/pixel.ts  (inside a service directory with an encore.service.ts)
import { api } from 'encore.dev/api';

const GIF = Buffer.from('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==', 'base64');

// A raw endpoint gets Node's req/res, so the bytes are written untouched.
export const pixel = api.raw(
  { expose: true, method: 'GET', path: '/pixel.gif' },
  async (req, resp) => {
    resp.writeHead(200, {
      'Content-Type': 'image/gif',
      'Content-Length': GIF.length,
      'Cache-Control': 'no-store',
    });
    resp.end(GIF);
  },
);

फ्रेमवर्कच्या सध्याच्या डॉक्युमेंटेशनशी जुळवून तपासले.

तपासा

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

अधिकृत साइट: Encore.ts

TypeScript मध्ये आणखी