emptygif
语言: 简体中文

所有语言和框架

Google Cloud Run functions (Node.js) JavaScript

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

Google Cloud Run functions (Node.js) JavaScript

安装
npm i @google-cloud/functions-framework
文件
index.mjs
运行
npx functions-framework --target=pixel --port=8080
import * as functions from '@google-cloud/functions-framework';

const GIF = Buffer.from('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==', 'base64');

functions.http('pixel', (req, res) => {
  if (req.path !== '/pixel.gif') {
    res.sendStatus(404);
    return;
  }
  res.set('Cache-Control', 'no-store').type('gif').send(GIF);
});

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

验证

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

官方网站: Google Cloud Run functions (Node.js)

更多 JavaScript 示例