emptygif
اللغة: العربية

كل اللغات وأطر العمل

Firebase Cloud Functions + Hosting JavaScript

مقتطف بلغة JavaScript لـ Firebase Cloud Functions + Hosting يستجيب لطلبات /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