emptygif
Harshe: Hausa

Duk harsuna da frameworks

AWS Lambda@Edge (CloudFront) JavaScript

Snippet na JavaScript don AWS Lambda@Edge (CloudFront) da ke amsa requests zuwa /pixel.gif da empty GIF, wanda ake decoding ɗinsa sau ɗaya lokacin farawa.

AWS Lambda@Edge (CloudFront) JavaScript

Fayil
index.js
// Viewer-request trigger: answer /pixel.gif at the edge, pass everything else through.
const GIF_BASE64 = 'R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';

exports.handler = async (event) => {
  const request = event.Records[0].cf.request;
  if (request.uri !== '/pixel.gif') return request;
  return {
    status: '200',
    statusDescription: 'OK',
    headers: {
      'content-type': [{ key: 'Content-Type', value: 'image/gif' }],
      'cache-control': [{ key: 'Cache-Control', value: 'no-store' }],
    },
    body: GIF_BASE64,
    bodyEncoding: 'base64',
  };
};

Mun gudanar da wannan snippet kuma mun kwatanta bytes ɗin da ya mayar.

Duba shi

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

Shafin hukuma: AWS Lambda@Edge (CloudFront)

Ƙari a JavaScript