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 範例