Demo entry 6729607

replaceimg

   

Submitted by anonymous on Apr 03, 2018 at 10:08
Language: JavaScript. Code size: 551 Bytes.

const { isReplaceImg } = config;
let imgBuf;
if (isReplaceImg) imgBuf = fs.readFileSync(path.join(__dirname, './replaceImg.png'));

  // 发送请求前拦截处理
  *beforeSendRequest(requestDetail) {
    const { requestOptions } = requestDetail;
    const { headers } = requestOptions;
    const { Accept } = headers;

    // 处理图片返回
    if (isReplaceImg && /^image/.test(Accept)) {
      return {
        response: {
          statusCode: 200,
          header: { 'content-type': 'image/png' },
          body: imgBuf
        }
      };
    }
  }

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).