emptygif
言語: 日本語

すべての言語・フレームワーク

Firebase Cloud Functions + Hosting JavaScript

/pixel.gif へのリクエストに空の GIF を返す、Firebase Cloud Functions + Hosting 用の JavaScript スニペット。GIF は起動時に一度だけデコードします。

Firebase Cloud Functions + Hosting JavaScript

インストール
npm i firebase-functions firebase-admin
ファイル
index.js
実行
firebase emulators:start
// functions/index.js - and in firebase.json:
//   "hosting": { "rewrites": [{ "source": "/pixel.gif", "function": { "functionId": "pixel" } }] }
import { onRequest } from 'firebase-functions/https';

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

export const pixel = onRequest((req, res) => {
  res.set('Cache-Control', 'no-store').type('gif').send(GIF);
});

このスニペットはコンパイルまたは型チェックしました。

確認

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

公式サイト: Firebase Cloud Functions + Hosting

JavaScript の他の例