Skip to content

Commit b36fb57

Browse files
- changed name of WTP_LS_ALLOW_REGEX to WTP_LS_ALLOWED_LOCATIONS_REGEX (#100)
- introduced a new option WTP_LS_ENABLED
1 parent 4768b7c commit b36fb57

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

config/default.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ const conf = {
3737
},
3838
timeout: process.env.WTP_TIMEOUT || 30000,
3939
"locationSelector": {
40-
"allowRegex": process.env.WTP_LS_ALLOW_REGEX || '_US_',
40+
"enabled": process.env.WTP_LS_ENABLED || false,
41+
"allowedLocationsRegex": process.env.WTP_LS_ALLOWED_LOCATIONS_REGEX || '_US_',
4142
"cacheTtl": process.env.WTP_LS_CACHE_TTL || 10,
4243
"updateTimeout": process.env.WTP_LS_UPDATE_TIMEOUT || 20,
4344
"defaultLocation": process.env.WTP_LS_DEFAULT_LOCATION || "IAD_US_01"

wtp/locationSelector.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ const locationMetrics = {
2929
class LocationSelector {
3030
constructor() {
3131
if (!LocationSelector.instance) {
32+
this.enabled = config.get('wtp.locationSelector.enabled');
3233
this.cachedAllLocations = [];
3334
this.location = config.get('wtp.locationSelector.defaultLocation');
34-
this.allowRegex = new RegExp(config.get('wtp.locationSelector.allowRegex'));
35+
this.allowedLocationsRegex = new RegExp(config.get('wtp.locationSelector.allowedLocationsRegex'));
3536
this.lastUpdated = null;
3637
this.mutex = withTimeout(new Mutex(), config.get('wtp.locationSelector.updateTimeout') * 1000);
3738
LocationSelector.instance = this;
@@ -114,7 +115,7 @@ class LocationSelector {
114115
}
115116

116117
const filtered = Object.keys(newLocations)
117-
.filter(key => this.allowRegex.test(key))
118+
.filter(key => this.allowedLocationsRegex.test(key))
118119
.reduce((arr, key) => {
119120
return [...arr, newLocations[key]];
120121
}, []);
@@ -154,7 +155,7 @@ class LocationSelector {
154155
};
155156

156157
async getLocation() {
157-
if (this.isExpired()) {
158+
if (this.enabled && this.isExpired()) {
158159
try {
159160
await this.mutex.runExclusive(async () => {
160161
if (this.isExpired()) {

0 commit comments

Comments
 (0)