node-consul-service 1.0.4 → 1.0.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/index.cjs.js +18 -10
- package/dist/index.esm.js +18 -10
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -36,24 +36,32 @@ client.agent.self((err) => {
|
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
const registeredServices = new Set();
|
|
39
|
-
async function registerService(
|
|
39
|
+
async function registerService(options) {
|
|
40
|
+
var _a, _b, _c, _d, _e;
|
|
41
|
+
const { name, id, port, address = 'localhost', check, tags, meta, } = options;
|
|
40
42
|
if (registeredServices.has(id)) {
|
|
41
43
|
console.log(`⚠️ Service "${id}" is already registered.`);
|
|
42
44
|
return;
|
|
43
45
|
}
|
|
44
|
-
|
|
46
|
+
const serviceDefinition = {
|
|
45
47
|
name,
|
|
46
48
|
id,
|
|
47
49
|
address,
|
|
48
50
|
port,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
tags,
|
|
52
|
+
meta,
|
|
53
|
+
};
|
|
54
|
+
// لو check مش موجود نضيف واحد افتراضي
|
|
55
|
+
if (check !== false) {
|
|
56
|
+
serviceDefinition.check = {
|
|
57
|
+
name: (_a = check === null || check === void 0 ? void 0 : check.name) !== null && _a !== void 0 ? _a : `${name}-check`,
|
|
58
|
+
http: (_b = check === null || check === void 0 ? void 0 : check.http) !== null && _b !== void 0 ? _b : `http://${address}:${port}/health`,
|
|
59
|
+
interval: (_c = check === null || check === void 0 ? void 0 : check.interval) !== null && _c !== void 0 ? _c : '10s',
|
|
60
|
+
timeout: (_d = check === null || check === void 0 ? void 0 : check.timeout) !== null && _d !== void 0 ? _d : '5s',
|
|
61
|
+
deregistercriticalserviceafter: (_e = check === null || check === void 0 ? void 0 : check.deregistercriticalserviceafter) !== null && _e !== void 0 ? _e : '1m',
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
await client.agent.service.register(serviceDefinition);
|
|
57
65
|
registeredServices.add(id);
|
|
58
66
|
console.log(`✅ Service "${id}" registered successfully.`);
|
|
59
67
|
}
|
package/dist/index.esm.js
CHANGED
|
@@ -34,24 +34,32 @@ client.agent.self((err) => {
|
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
const registeredServices = new Set();
|
|
37
|
-
async function registerService(
|
|
37
|
+
async function registerService(options) {
|
|
38
|
+
var _a, _b, _c, _d, _e;
|
|
39
|
+
const { name, id, port, address = 'localhost', check, tags, meta, } = options;
|
|
38
40
|
if (registeredServices.has(id)) {
|
|
39
41
|
console.log(`⚠️ Service "${id}" is already registered.`);
|
|
40
42
|
return;
|
|
41
43
|
}
|
|
42
|
-
|
|
44
|
+
const serviceDefinition = {
|
|
43
45
|
name,
|
|
44
46
|
id,
|
|
45
47
|
address,
|
|
46
48
|
port,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
tags,
|
|
50
|
+
meta,
|
|
51
|
+
};
|
|
52
|
+
// لو check مش موجود نضيف واحد افتراضي
|
|
53
|
+
if (check !== false) {
|
|
54
|
+
serviceDefinition.check = {
|
|
55
|
+
name: (_a = check === null || check === void 0 ? void 0 : check.name) !== null && _a !== void 0 ? _a : `${name}-check`,
|
|
56
|
+
http: (_b = check === null || check === void 0 ? void 0 : check.http) !== null && _b !== void 0 ? _b : `http://${address}:${port}/health`,
|
|
57
|
+
interval: (_c = check === null || check === void 0 ? void 0 : check.interval) !== null && _c !== void 0 ? _c : '10s',
|
|
58
|
+
timeout: (_d = check === null || check === void 0 ? void 0 : check.timeout) !== null && _d !== void 0 ? _d : '5s',
|
|
59
|
+
deregistercriticalserviceafter: (_e = check === null || check === void 0 ? void 0 : check.deregistercriticalserviceafter) !== null && _e !== void 0 ? _e : '1m',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
await client.agent.service.register(serviceDefinition);
|
|
55
63
|
registeredServices.add(id);
|
|
56
64
|
console.log(`✅ Service "${id}" registered successfully.`);
|
|
57
65
|
}
|