resilient-consul
Version:
Resilient HTTP middleware for Consul service discovery and balancing
2 lines • 1.52 kB
JavaScript
(function(e,r){if(typeof define==="function"&&define.amd){define(["exports"],r)}else if(typeof exports==="object"){r(exports);if(typeof module==="object"&&module!==null){module.exports=exports=exports.resilientConsul}}else{r(e)}})(this,function(e){var r=["service","servers"];var t=["service","datacenter","protocol","tag","mapServers","onlyHealthy"];e.resilientConsul=function(e){e=n(e||{});var r=e.mapServers||(e.onlyHealthy?o:s);var t=e.onlyHealthy?"/v1/health/service/":"/v1/catalog/service/";e.basePath=t+e.service;if(e.discoveryService){e.refreshPath=t+e.discoveryService;e.enableSelfRefresh=true}function a(t,n){i(e,t);return{"in":function a(e,t,n){if(e)return n();if(Array.isArray(t.data)&&Object(t.data[0])===t.data[0]){t.data=r(t.data)}n()},out:function o(r,t){r.params=r.params||{};if(e.datacenter){r.params.dc=e.datacenter}if(e.onlyHealthy){r.params.passing=true}if(e.tag){r.params.tag=e.tag}t()}}}a.type="discovery";return a;function o(r){return r.map(function t(r){return(e.protocol||"http")+"://"+r.Service.Address+":"+(+r.Service.Port||80)})}function s(r){return r.map(function t(r){return(e.protocol||"http")+"://"+(r.ServiceAddress||r.Address)+":"+(+r.ServicePort||80)})}};function n(e){var t=r.filter(function(r){return!e[r]});if(t.length){throw new TypeError("Missing required params: "+t.join(", "))}return e}function i(e,r){Object.keys(e).filter(function(e){return!~t.indexOf(e)}).forEach(function(t){r.set(t,e[t])})}});
//# sourceMappingURL=http://cdn.rawgit.com/h2non/consul/0.1.7/consul.min.js.map