feature: 拦截配置,支持排除配置(`exclusions`) (#356)

pull/360/head
王良 3 months ago committed by GitHub
parent 0e8f3a99e9
commit f3353fbb1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -116,6 +116,21 @@ module.exports = (serverConfig) => {
const interceptOpt = interceptOpts[regexp] const interceptOpt = interceptOpts[regexp]
// interceptOpt.key = regexp // interceptOpt.key = regexp
// 添加exclusions字段用于排除某些路径
// @since 1.8.5
if (Array.isArray(interceptOpt.exclusions) && interceptOpt.exclusions.length > 0) {
let isExcluded = false
for (const exclusion of interceptOpt.exclusions) {
if (matchUtil.isMatched(rOptions.path, exclusion)) {
log.debug(`拦截器配置排除了path${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${rOptions.path}, exclusion: '${exclusion}', interceptOpt:`, interceptOpt)
isExcluded = true
}
}
if (isExcluded) {
continue
}
}
log.debug(`拦截器匹配path成功${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${rOptions.path}, regexp: ${regexp}, interceptOpt:`, interceptOpt) log.debug(`拦截器匹配path成功${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${rOptions.path}, regexp: ${regexp}, interceptOpt:`, interceptOpt)
// log.info(`interceptor matched, regexp: '${regexp}' =>`, JSON.stringify(interceptOpt), ', url:', url) // log.info(`interceptor matched, regexp: '${regexp}' =>`, JSON.stringify(interceptOpt), ', url:', url)

@ -151,7 +151,7 @@ function matchHostnameAll (hostMap, hostname, action) {
// 正则表达式匹配 // 正则表达式匹配
if (hostname.match(regexp)) { if (hostname.match(regexp)) {
value = hostMap[target] value = hostMap[target]
log.info(`matchHostname-one: ${action}: '${hostname}' -> '${target}': ${JSON.stringify(value)}`) log.debug(`matchHostname-one: ${action}: '${hostname}' -> '${target}': ${JSON.stringify(value)}`)
values = merge(values, value) values = merge(values, value)
} }
} }
@ -160,19 +160,19 @@ function matchHostnameAll (hostMap, hostname, action) {
// 优先级2 // 优先级2
value = hostMap.origin['*' + hostname] value = hostMap.origin['*' + hostname]
if (value) { if (value) {
log.info(`matchHostname-one: ${action}: '${hostname}' -> '*${hostname}': ${JSON.stringify(value)}`) log.debug(`matchHostname-one: ${action}: '${hostname}' -> '*${hostname}': ${JSON.stringify(value)}`)
values = merge(values, value) values = merge(values, value)
} }
// 优先级3 // 优先级3
value = hostMap.origin['*.' + hostname] value = hostMap.origin['*.' + hostname]
if (value) { if (value) {
log.info(`matchHostname-one: ${action}: '${hostname}' -> '*.${hostname}': ${JSON.stringify(value)}`) log.debug(`matchHostname-one: ${action}: '${hostname}' -> '*.${hostname}': ${JSON.stringify(value)}`)
values = merge(values, value) values = merge(values, value)
} }
// 优先级4最高优先级高的配置可以覆盖优先级低的配置甚至有空配置时可以移除已有配置 // 优先级4最高优先级高的配置可以覆盖优先级低的配置甚至有空配置时可以移除已有配置
value = hostMap.origin[hostname] value = hostMap.origin[hostname]
if (value) { if (value) {
log.info(`matchHostname-one: ${action}: '${hostname}' -> '${hostname}': ${JSON.stringify(value)}`) log.debug(`matchHostname-one: ${action}: '${hostname}' -> '${hostname}': ${JSON.stringify(value)}`)
values = merge(values, value) values = merge(values, value)
} }

Loading…
Cancel
Save