Azure Functions (Node.js v4 model) JavaScript
一个用于 Azure Functions (Node.js v4 model) 的 JavaScript 代码片段,以空 GIF 响应对 /pixel.gif 的请求,GIF 在启动时只解码一次。
Azure Functions (Node.js v4 model) JavaScript
// 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)