feature: 拦截配置,支持排除配置(`exclusions`) (#356)
parent
0e8f3a99e9
commit
f3353fbb1d
|
@ -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…
Reference in New Issue