emptygif
언어: 한국어

모든 언어 및 프레임워크

Azure Functions (Node.js v4 model) JavaScript

/pixel.gif 요청에 빈 GIF로 응답하는 Azure Functions (Node.js v4 model)용 JavaScript 스니펫입니다. GIF는 시작할 때 한 번만 디코딩합니다.

Azure Functions (Node.js v4 model) JavaScript

설치
npm i @azure/functions
파일
pixel.js
실행
func start
// src/functions/pixel.js
import { app } from '@azure/functions';

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

app.http('pixel', {
  methods: ['GET'],
  authLevel: 'anonymous',
  // Routes have no leading slash and sit under the "api" prefix unless
  // extensions.http.routePrefix is set to "" in host.json.
  route: '/pixel.gif'.slice(1),
  handler: async () => ({
    body: GIF,
    headers: {
      'Content-Type': 'image/gif',
      'Content-Length': String(GIF.length),
      'Cache-Control': 'no-store',
    },
  }),
});

이 스니펫은 실행해 보고, 반환된 바이트를 비교했습니다.

확인

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

공식 사이트: Azure Functions (Node.js v4 model)

JavaScript의 다른 예제