腾讯云控制台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);
  }
);


})
相关推荐
共享家95273 小时前
搭建 AI 聊天机器人:”我的人生我做主“
前端·javascript·css·python·pycharm·html·状态模式
摘星编程5 小时前
OpenHarmony环境下React Native:自定义useTruncate文本截断
javascript·react native·react.js
珠海西格5 小时前
“主动预防” vs “事后补救”:分布式光伏防逆流技术的代际革命,西格电力给出标准答案
大数据·运维·服务器·分布式·云计算·能源
Duang007_5 小时前
【LeetCodeHot100 超详细Agent启发版本】字母异位词分组 (Group Anagrams)
开发语言·javascript·人工智能·python
2601_949868367 小时前
Flutter for OpenHarmony 电子合同签署App实战 - 主入口实现
开发语言·javascript·flutter
m0_748229997 小时前
Vue2 vs Vue3:核心差异全解析
前端·javascript·vue.js
xiaoxue..7 小时前
React 手写实现的 KeepAlive 组件
前端·javascript·react.js·面试
摘星编程7 小时前
在OpenHarmony上用React Native:自定义useHighlight关键词高亮
javascript·react native·react.js
2601_949613028 小时前
flutter_for_openharmony家庭药箱管理app实战+用药知识详情实现
android·javascript·flutter
一起养小猫8 小时前
Flutter for OpenHarmony 实战 表单处理与验证完整指南
android·开发语言·前端·javascript·flutter·harmonyos