emptygif
Ngôn ngữ: Tiếng Việt

Tất cả ngôn ngữ và framework

Oak TypeScript

Đoạn mã TypeScript cho Oak, trả lời các yêu cầu tới /pixel.gif bằng GIF rỗng, được giải mã một lần khi khởi động.

Oak TypeScript

Tệp
server.ts
Chạy
deno run --allow-net server.ts
import { Application, Router } from 'jsr:@oak/oak';
import { decodeBase64 } from 'jsr:@std/encoding/base64';

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

const router = new Router();
router.get('/pixel.gif', (ctx) => {
  ctx.response.type = 'image/gif';
  ctx.response.headers.set('Cache-Control', 'no-store');
  ctx.response.body = GIF;
});

const app = new Application();
app.use(router.routes());
await app.listen({ port: 8080 });

Chúng tôi đã chạy đoạn mã này và so sánh các byte nó trả về.

Kiểm tra

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

Trang chính thức: Oak

Thêm với TypeScript