@routr/location 2.0.8-alpha.4 → 2.0.8-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/get_config.js +8 -7
- package/dist/location.js +1 -1
- package/dist/service.js +1 -1
- package/dist/types.d.ts +4 -4
- package/dist/types.js +11 -11
- package/package.json +4 -4
|
@@ -53,9 +53,10 @@ const E = __importStar(require("fp-ts/Either"));
|
|
|
53
53
|
const errors_1 = require("../errors");
|
|
54
54
|
const ajv = new ajv_1.default();
|
|
55
55
|
const validate = ajv.compile(schema_1.schema);
|
|
56
|
-
const hasBadCombiniation = (backends) => backends.some((b) => b.balancingAlgorithm === types_1.
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
const hasBadCombiniation = (backends) => backends.some((b) => b.balancingAlgorithm === types_1.LoadBalancingAlgorithm.ROUND_ROBIN &&
|
|
57
|
+
b.withSessionAffinity);
|
|
58
|
+
const hasBadAlgorithm = (backends) => backends.some((b) => b.balancingAlgorithm !== types_1.LoadBalancingAlgorithm.ROUND_ROBIN &&
|
|
59
|
+
b.balancingAlgorithm !== types_1.LoadBalancingAlgorithm.LEAST_SESSIONS);
|
|
59
60
|
const getConfig = (path) => {
|
|
60
61
|
var _a, _b, _c;
|
|
61
62
|
const c = JSON.parse(fs_1.default.readFileSync(path, "utf8"));
|
|
@@ -68,7 +69,7 @@ const getConfig = (path) => {
|
|
|
68
69
|
// Setting round-robin by default
|
|
69
70
|
b.balancingAlgorithm = b.balancingAlgorithm
|
|
70
71
|
? b.balancingAlgorithm
|
|
71
|
-
: types_1.
|
|
72
|
+
: types_1.LoadBalancingAlgorithm.ROUND_ROBIN;
|
|
72
73
|
return b;
|
|
73
74
|
});
|
|
74
75
|
if (hasBadCombiniation(config.backends)) {
|
|
@@ -80,13 +81,13 @@ const getConfig = (path) => {
|
|
|
80
81
|
}
|
|
81
82
|
if (!((_a = config === null || config === void 0 ? void 0 : config.cache) === null || _a === void 0 ? void 0 : _a.provider)) {
|
|
82
83
|
config.cache = {
|
|
83
|
-
provider: types_1.
|
|
84
|
+
provider: types_1.CacheProvider.MEMORY
|
|
84
85
|
};
|
|
85
86
|
}
|
|
86
|
-
if (((_b = config === null || config === void 0 ? void 0 : config.cache) === null || _b === void 0 ? void 0 : _b.provider) === types_1.
|
|
87
|
+
if (((_b = config === null || config === void 0 ? void 0 : config.cache) === null || _b === void 0 ? void 0 : _b.provider) === types_1.CacheProvider.REDIS &&
|
|
87
88
|
!((_c = config === null || config === void 0 ? void 0 : config.cache) === null || _c === void 0 ? void 0 : _c.parameters)) {
|
|
88
89
|
config.cache = {
|
|
89
|
-
provider: types_1.
|
|
90
|
+
provider: types_1.CacheProvider.REDIS,
|
|
90
91
|
parameters: "host=localhost,port=6379"
|
|
91
92
|
};
|
|
92
93
|
}
|
package/dist/location.js
CHANGED
|
@@ -89,7 +89,7 @@ class Location {
|
|
|
89
89
|
}
|
|
90
90
|
// eslint-disable-next-line require-jsdoc
|
|
91
91
|
next(routes, backend) {
|
|
92
|
-
if (backend.balancingAlgorithm === types_1.
|
|
92
|
+
if (backend.balancingAlgorithm === types_1.LoadBalancingAlgorithm.LEAST_SESSIONS) {
|
|
93
93
|
return routes.sort((r1, r2) => r1.sessionCount - r2.sessionCount)[0];
|
|
94
94
|
}
|
|
95
95
|
// Continues using round-robin
|
package/dist/service.js
CHANGED
|
@@ -38,7 +38,7 @@ const allowedParameters = ["host", "port", "username", "password", "secure"];
|
|
|
38
38
|
function LocationService(config) {
|
|
39
39
|
const { bindAddr, cache } = config;
|
|
40
40
|
let store;
|
|
41
|
-
if (cache.provider === types_1.
|
|
41
|
+
if (cache.provider === types_1.CacheProvider.REDIS) {
|
|
42
42
|
store = new redis_store_1.default((0, utils_1.configFromString)(cache.parameters, allowedParameters));
|
|
43
43
|
}
|
|
44
44
|
else {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Route } from "@routr/common";
|
|
2
|
-
export declare enum
|
|
2
|
+
export declare enum LoadBalancingAlgorithm {
|
|
3
3
|
ROUND_ROBIN = "round-robin",
|
|
4
4
|
LEAST_SESSIONS = "least-sessions"
|
|
5
5
|
}
|
|
6
|
-
export declare enum
|
|
6
|
+
export declare enum CacheProvider {
|
|
7
7
|
MEMORY = "memory",
|
|
8
8
|
REDIS = "redis"
|
|
9
9
|
}
|
|
@@ -34,14 +34,14 @@ export interface RemoveRoutesRequest {
|
|
|
34
34
|
}
|
|
35
35
|
export interface Backend {
|
|
36
36
|
ref: string;
|
|
37
|
-
balancingAlgorithm?:
|
|
37
|
+
balancingAlgorithm?: LoadBalancingAlgorithm;
|
|
38
38
|
withSessionAffinity?: boolean;
|
|
39
39
|
}
|
|
40
40
|
export interface LocationConfig {
|
|
41
41
|
bindAddr: string;
|
|
42
42
|
backends?: Backend[];
|
|
43
43
|
cache?: {
|
|
44
|
-
provider:
|
|
44
|
+
provider: CacheProvider;
|
|
45
45
|
parameters?: string;
|
|
46
46
|
};
|
|
47
47
|
}
|
package/dist/types.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
(function (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
})(
|
|
9
|
-
var
|
|
10
|
-
(function (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
})(
|
|
3
|
+
exports.CacheProvider = exports.LoadBalancingAlgorithm = void 0;
|
|
4
|
+
var LoadBalancingAlgorithm;
|
|
5
|
+
(function (LoadBalancingAlgorithm) {
|
|
6
|
+
LoadBalancingAlgorithm["ROUND_ROBIN"] = "round-robin";
|
|
7
|
+
LoadBalancingAlgorithm["LEAST_SESSIONS"] = "least-sessions";
|
|
8
|
+
})(LoadBalancingAlgorithm = exports.LoadBalancingAlgorithm || (exports.LoadBalancingAlgorithm = {}));
|
|
9
|
+
var CacheProvider;
|
|
10
|
+
(function (CacheProvider) {
|
|
11
|
+
CacheProvider["MEMORY"] = "memory";
|
|
12
|
+
CacheProvider["REDIS"] = "redis";
|
|
13
|
+
})(CacheProvider = exports.CacheProvider || (exports.CacheProvider = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@routr/location",
|
|
3
|
-
"version": "2.0.8-alpha.
|
|
3
|
+
"version": "2.0.8-alpha.5",
|
|
4
4
|
"description": "Creates and maintains a list of routes to all registered endpoints",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/routr#readme",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"@opentelemetry/sdk-trace-base": "^1.0.4",
|
|
36
36
|
"@opentelemetry/sdk-trace-node": "^1.0.4",
|
|
37
37
|
"@opentelemetry/semantic-conventions": "^1.0.4",
|
|
38
|
-
"@routr/common": "^2.0.8-alpha.
|
|
39
|
-
"@routr/processor": "^2.0.8-alpha.
|
|
38
|
+
"@routr/common": "^2.0.8-alpha.5",
|
|
39
|
+
"@routr/processor": "^2.0.8-alpha.5",
|
|
40
40
|
"ajv": "^6.12.6",
|
|
41
41
|
"fp-ts": "^2.11.8",
|
|
42
42
|
"redis": "^4.0.4"
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"bugs": {
|
|
49
49
|
"url": "https://github.com/fonoster/routr/issues"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "215638b9d7b56b2db2c2f0bc1bada3b6accbde58"
|
|
52
52
|
}
|