如图所示的俩个控制台功能,调用腾讯云的接口执行这俩个动作 (代码可以优化)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);
}
);
})