Firebase Cloud Functions + Hosting JavaScript
/pixel.gif 요청에 빈 GIF로 응답하는 Firebase Cloud Functions + Hosting용 JavaScript 스니펫입니다. GIF는 시작할 때 한 번만 디코딩합니다.
Firebase Cloud Functions + Hosting JavaScript
// 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