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

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

Bun.serve TypeScript

Đoạn mã TypeScript cho Bun.serve, 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.

Bun.serve TypeScript

Tệp
server.ts
Chạy
bun server.ts
const GIF = Buffer.from('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==', 'base64');

Bun.serve({
  port: 8080,
  routes: {
    // A static Response is built once and served for every request.
    '/pixel.gif': new Response(GIF, {
      headers: { 'Content-Type': 'image/gif', 'Cache-Control': 'no-store' },
    }),
  },
});

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: Bun.serve

Thêm với TypeScript