emptygif
語言: 繁體中文

所有語言和框架

Firebase Cloud Functions + Hosting JavaScript

適用於 Firebase Cloud Functions + Hosting 的 JavaScript 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,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 範例