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

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

Azure Functions (Node.js v4 model) JavaScript

مقتطف بلغة JavaScript لـ Azure Functions (Node.js v4 model) يستجيب لطلبات /pixel.gif بملف 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