UNPKG

api-service-core

Version:

NodeJS api-service

51 lines 1.92 kB
"use strict"; /************************************************************************* * * Troven CONFIDENTIAL * __________________ * * (c) 2017-2019 Troven Pty Ltd * All Rights Reserved. * * NOTICE: All information contained herein is, and remains * the property of Troven Pty Ltd and its licensors, * if any. The intellectual and technical concepts contained * herein are proprietary to Troven Pty Ltd * and its suppliers and may be covered by International and Regional Patents, * patents in process, and are protected by trade secret or copyright law. * Dissemination of this information or reproduction of this material * is strictly forbidden unless prior written permission is obtained * from Troven Pty Ltd. */ Object.defineProperty(exports, "__esModule", { value: true }); const assert = require("assert"); const _ = require("lodash"); /** * Gregarious * ---------- * Feature adds an X-CHASSIS method that reports the chassis name and port. * * @type {{name: string, title: string, description: string, fn: module.exports.fn}} */ class gregarious { constructor() { this.name = "api.gregarious"; this.title = "internal service headers"; } fn(operation, options) { let _pkg_name = operation.context.pkg.name; let _name = operation.context.config.name || _pkg_name; let _version = operation.context.pkg.version || "0.0.0"; let _options = options; return function (req, res, next) { assert(req && res && next, "invalid middleware"); res.header("X-SERVICE-ID", _name); res.header("X-SERVICE-UUID", operation.context.uuid); res.header("X-SERVICE-RELEASE", _pkg_name + " v" + _version); _.each(_options.headers, function (v, k) { res.header(k, v); }); next(); }; } } exports.default = gregarious; //# sourceMappingURL=gregarious.js.map