express-gateway-service-registry
Version:
With self-registration, each microservice is responsible for adding itself to the gateway when it comes online.
82 lines • 2.27 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.GatewayService = void 0;
const tslib_1 = require("tslib");
const core_1 = require("@loopback/core");
const axios_1 = tslib_1.__importDefault(require("axios"));
const keys_1 = require("../keys");
class ApiService {
constructor() {
this.http = axios_1.default;
}
get(path, params) {
return this.http.get(`${this.baseUrl}${path}`, { params });
}
;
async put(path, body) {
console.log(`${this.baseUrl}${path}`, body);
try {
const response = await this.http.put(`${this.baseUrl}${path}`, body);
return response.data;
}
catch (err) {
throw new Error(err);
}
}
;
post(path, body) {
return this.http.post(`${this.baseUrl}${path}`, body);
}
;
delete(path) {
return this.http.delete(`${this.baseUrl}${path}`);
}
;
}
let GatewayService = class GatewayService extends ApiService {
constructor(gc) {
super();
const defaultValue = {
baseUrl: "http://localhost:8081",
apiBaseUrl: "http://localhost:9876"
};
if (!gc.gateway) {
gc.gateway = defaultValue;
}
this.baseUrl = gc.gateway.apiBaseUrl;
}
/**
*
* @param name
* @param data
* @returns
*/
registerApiEndPoint(name, data) {
return this.put(`/api-endpoints/${name}`, data);
}
/**
*
* @param serviceEndPointName
* @param data
* @returns
*/
registerServiceEndPoints(serviceEndPointName, data) {
return this.put(`/service-endpoints/${serviceEndPointName}`, data);
}
/**
*
* @param name
* @param data
* @returns
*/
registerPipelines(name, data) {
return this.put(`/pipelines/${name}`, data);
}
};
GatewayService = tslib_1.__decorate([
(0, core_1.bind)({ scope: core_1.BindingScope.TRANSIENT }),
tslib_1.__param(0, (0, core_1.inject)(keys_1.GatewayServiceRegistryComponentBindings.CONFIG)),
tslib_1.__metadata("design:paramtypes", [Object])
], GatewayService);
exports.GatewayService = GatewayService;
//# sourceMappingURL=gateway.service.js.map
;