@magnet.me/consultant 1.3.1 → 1.3.2
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/out/service.js +3 -3
- package/out/service.js.map +1 -1
- package/package.json +1 -1
package/out/service.js
CHANGED
|
@@ -16,8 +16,8 @@ var _identifier = _interopRequireDefault(require("./identifier"));
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
|
|
18
18
|
const deregister = async (host, instance) => {
|
|
19
|
-
const
|
|
20
|
-
|
|
19
|
+
const uri = `${host}/v1/agent/service/deregister/${instance.instance}`;
|
|
20
|
+
const opts = {
|
|
21
21
|
method: 'PUT',
|
|
22
22
|
headers: {
|
|
23
23
|
'user-agent': _properties.default.userAgent
|
|
@@ -25,7 +25,7 @@ const deregister = async (host, instance) => {
|
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
try {
|
|
28
|
-
await (0, _nodeFetch.default)(
|
|
28
|
+
await (0, _nodeFetch.default)(uri, opts);
|
|
29
29
|
} catch (e) {
|
|
30
30
|
throw new _consultantError.default(`Could not deregister from Consul: ${e}`);
|
|
31
31
|
}
|
package/out/service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/service.js"],"names":["deregister","host","instance","
|
|
1
|
+
{"version":3,"sources":["../src/service.js"],"names":["deregister","host","instance","uri","opts","method","headers","properties","userAgent","e","ConsultantError","register","service","healthCheckPath","healthCheckInterval","consulHost","process","env","CONSUL_HOST","defaultHost","portNumber","Number","port","name","identifier","body","Id","Name","Address","Port","Object","assign","Check","HTTP","Interval","url","JSON","stringify"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;;;AAEA,MAAMA,UAAU,GAAG,OAAOC,IAAP,EAAaC,QAAb,KAA0B;AAC5C,QAAMC,GAAG,GAAI,GAAEF,IAAK,gCAA+BC,QAAQ,CAACA,QAAS,EAArE;AACA,QA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cN,IAAd,EAAoB;AACnBO,MAAAA,KAAK,EAAG;AACPC,QAAAA,IAAI,EAAI,UAAST,UAAU,CAACvB,IAAK,IAAGW,OAAO,CAACU,IAAK,GAAET,eAAgB,EAD5D;AAEPqB,QAAAA,QAAQ,EAAGpB;AAFJ;AADW,KAApB;AAMA;;AAED,QAAMqB,GAAG,GAAI,GAAEpB,UAAW,4BAA1B;AACA,QAAMX,IAAI,GAAG;AACZC,IAAAA,MAAM,EAAG,KADG;AAEZC,IAAAA,OAAO,EAAG;AACT,gBAAW,kBADF;AAET,sBAAiB,kBAFR;AAGT,oBAAeC,oBAAWC;AAHjB,KAFE;AAOZiB,IAAAA,IAAI,EAAGW,IAAI,CAACC,SAAL,CAAeZ,IAAf;AAPK,GAAb;;AAUA,MAAI;AACH,UAAM,wBAAMU,GAAN,EAAW/B,IAAX,CAAN;AACA,GAFD,CAGA,OAAOK,CAAP,EAAU;AACT,UAAM,IAAIC,wBAAJ,CAAoB,wCAApB,EAA8DD,CAA9D,CAAN;AACA;;AAED,SAAO;AACNe,IAAAA,UADM;AAENxB,IAAAA,UAAU,EAAG,MAAMA,UAAU,CAACe,UAAD,EAAaS,UAAb;AAFvB,GAAP;AAIA","sourcesContent":["import fetch from 'node-fetch';\nimport ConsultantError from './consultant-error';\nimport properties from './properties';\nimport fetchIdentifier from './identifier';\n\nconst deregister = async (host, instance) => {\n\tconst uri = `${host}/v1/agent/service/deregister/${instance.instance}`;\n\tconst opts = {\n\t\tmethod : 'PUT',\n\t\theaders : {\n\t\t\t'user-agent' : properties.userAgent\n\t\t}\n\t};\n\n\ttry {\n\t\tawait fetch(uri, opts);\n\t}\n\tcatch (e) {\n\t\tthrow new ConsultantError(`Could not deregister from Consul: ${e}`);\n\t}\n};\n\nexport default async function register({service, healthCheckPath, healthCheckInterval = 10, consulHost}) {\n\tconsulHost = consulHost || process.env.CONSUL_HOST || properties.defaultHost;\n\n\tconst portNumber = Number(service.port);\n\tif (!(portNumber > 0 && portNumber < 65536)) {\n\t\tthrow new ConsultantError(`service.port=${service.port} is not a proper port`);\n\t}\n\n\tif (!service.name) {\n\t\tthrow new ConsultantError('service.name was not defined');\n\t}\n\n\tconst identifier = await fetchIdentifier(service, consulHost);\n\n\tconst body = {\n\t\tId : identifier.instance,\n\t\tName : identifier.name,\n\t\tAddress : identifier.host,\n\t\tPort : service.port,\n\t};\n\n\tif (healthCheckPath && healthCheckInterval > 0) {\n\t\tObject.assign(body, {\n\t\t\tCheck : {\n\t\t\t\tHTTP : `http://${identifier.host}:${service.port}${healthCheckPath}`,\n\t\t\t\tInterval : healthCheckInterval\n\t\t\t}\n\t\t});\n\t}\n\n\tconst url = `${consulHost}/v1/agent/service/register`;\n\tconst opts = {\n\t\tmethod : 'PUT',\n\t\theaders : {\n\t\t\t'accept' : 'application/json',\n\t\t\t'content-type' : 'application/json',\n\t\t\t'user-agent' : properties.userAgent\n\t\t},\n\t\tbody : JSON.stringify(body)\n\t};\n\n\ttry {\n\t\tawait fetch(url, opts);\n\t}\n\tcatch (e) {\n\t\tthrow new ConsultantError('Could not register service with Consul', e);\n\t}\n\n\treturn {\n\t\tidentifier,\n\t\tderegister : () => deregister(consulHost, identifier)\n\t};\n}\n"],"file":"service.js"}
|