腾讯云控制台URL刷新&&URL预热 使用接口刷新

如图所示的俩个控制台功能,调用腾讯云的接口执行这俩个动作 (代码可以优化)nodejs框架是express, 这里粘贴调用成功的代码示例,做个记录。

javascript 复制代码
app.get('/PurgeUrlsCache', async function (req, res, next) {
	// Depends on tencentcloud-sdk-nodejs version 4.0.3 or higher
const client = new tencentcloud.cdn.v20180606.Client({
  credential: {
    secretId: "XXX",
    secretKey: "XXX",
  },
  region: "",
  profile: {
    signMethod: "TC3-HMAC-SHA256",
    httpProfile: {
      reqMethod: "POST",
      reqTimeout: 30,
      endpoint: "cdn.tencentcloudapi.com",
    },
  },
})

const params = {
    "Urls": [
        req.query.url
    ]
};
// 清除CDN缓存
client.PurgeUrlsCache(params).then(
  (data) => {
    console.log(data);
  res.send(data);
  },
  (err) => {
    console.error("error", err);
  }
);


})



app.get('/urlspushcache', async function (req, res, next) {
	// Depends on tencentcloud-sdk-nodejs version 4.0.3 or higher
const client = new tencentcloud.cdn.v20180606.Client({
  credential: {
    secretId: "xxx",
    secretKey: "xxx",
  },
  region: "",
  profile: {
    signMethod: "TC3-HMAC-SHA256",
    httpProfile: {
      reqMethod: "POST",
      reqTimeout: 30,
      endpoint: "cdn.tencentcloudapi.com",
    },
  },
})

const params = {
    "Urls": [
        req.query.url
    ]
};
// 重新刷新预热
client.PushUrlsCache(params).then(
  (data) => {
    console.log(data);
  res.send(data);
  },
  (err) => {
    console.error("error", err);
  }
);


})
相关推荐
Icoolkj7 小时前
VuePress 与 VitePress 深度对比:特性、差异与选型指南
前端·javascript·vue.js
^Rocky8 小时前
JavaScript性能优化实战
开发语言·javascript·性能优化
AKAMAI9 小时前
Entity Digital Sports 降低成本并快速扩展
人工智能·云计算
西陵9 小时前
Nx带来极致的前端开发体验——任务编排
前端·javascript·架构
笑鸿的学习笔记9 小时前
JavaScript笔记之JS 和 HTML5 的关系
javascript·笔记·html5
荣光波比10 小时前
Nginx 实战系列(一)—— Web 核心概念、HTTP/HTTPS协议 与 Nginx 安装
linux·运维·服务器·nginx·云计算
萌萌哒草头将军11 小时前
10个 ES2025 新特性速览!🚀🚀🚀
前端·javascript·vue.js
gnip11 小时前
http缓存
前端·javascript
JohnYan12 小时前
工作笔记 - 微信消息发送和处理
javascript·后端·微信
陈陈爱java13 小时前
Spring八股文
开发语言·javascript·数据库