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 の他の例