emptygif
Wika: Filipino

Lahat ng language at framework

Encore.ts TypeScript

Isang TypeScript snippet para sa Encore.ts na sumasagot sa mga request sa /pixel.gif gamit ang empty GIF, na isang beses lang dine-decode sa startup.

Encore.ts TypeScript

I-install
encore app create --example=ts/hello-world
File
pixel.ts
Patakbuhin
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);
  },
);

Sinuri batay sa kasalukuyang dokumentasyon ng framework.

Suriin

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

Opisyal na site: Encore.ts

Iba pa sa TypeScript