emptygif
Harshe: Hausa

Duk harsuna da frameworks

Encore.ts TypeScript

Snippet na TypeScript don Encore.ts da ke amsa requests zuwa /pixel.gif da empty GIF, wanda ake decoding ɗinsa sau ɗaya lokacin farawa.

Encore.ts TypeScript

Girkawa
encore app create --example=ts/hello-world
Fayil
pixel.ts
Gudanar
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);
  },
);

An duba shi da takardun bayani na yanzu na framework ɗin.

Duba shi

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

Shafin hukuma: Encore.ts

Ƙari a TypeScript