emptygif
语言: 简体中文

所有语言和框架

AWS Lambda (Node.js) JavaScript

一个用于 AWS Lambda (Node.js) 的 JavaScript 代码片段,以空 GIF 响应对 /pixel.gif 的请求,GIF 在启动时只解码一次。

AWS Lambda (Node.js) JavaScript

文件
index.mjs
// index.mjs - behind an API Gateway HTTP API route "GET /pixel.gif" or a function URL.
// Binary bodies travel base64-encoded, so the GIF stays in base64 here.
const GIF_BASE64 = 'R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';

export const handler = async () => ({
  statusCode: 200,
  headers: { 'Content-Type': 'image/gif', 'Cache-Control': 'no-store' },
  body: GIF_BASE64,
  isBase64Encoded: true,
});

我们运行了此代码片段,并比对了它返回的字节。

验证

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

官方网站: AWS Lambda (Node.js)

更多 JavaScript 示例