tencentcloud-edgeone-migration-nodejs-v2
Version:
tencentcloud cdn config copy to edgeone
72 lines (67 loc) • 1.81 kB
JavaScript
const { t } = require("../../i18n/trans");
const genLog = require("../../logGenerator");
function PathRules(domain, domainConfig, ruleTransferLog) {
const keyConfig = domainConfig.Origin.PathRules;
if (!keyConfig || !keyConfig.length) {
ruleTransferLog.push({
config: t('回源路径重写规则配置(Origin.PathRules)'),
result: t('未配置'),
detail: ''
});
genLog.defaultLog(`${t('回源路径重写规则配置(Origin.PathRules)')}${t('未配置')}`)
return null;
}
const eoRules = [];
keyConfig.forEach(rule => {
eoRules.push({
'Conditions': [
{
'Conditions': [
{
'Operator': 'equal',
'Target': rule.FullMatch ? 'full_url' : 'url',
'IgnoreCase': false,
'Values': rule.FullMatch ? [`https://${domain}${rule.Path}`] : [rule.Path]
}
]
}
],
'Actions': [
{
'NormalAction': {
'Action': 'UpstreamUrlRedirect',
'Parameters': [
{
'Name': 'Type',
'Values': [
'Path'
]
},
{
'Name': 'Action',
'Values': [
'replace'
]
},
{
'Name': 'Value',
'Values': [rule.ForwardUri]
}
]
}
}
]
});
});
ruleTransferLog.push({
config: t('回源路径重写规则配置(Origin.PathRules)'),
result: t('成功'),
detail: ''
});
genLog.successLog(`${t('回源路径重写规则配置(Origin.PathRules)')}${t('成功')}`)
return {
'Rules': eoRules,
'Tags': []
};
}
module.exports = PathRules;