api-service-core
Version:
NodeJS api-service
50 lines • 1.8 kB
JavaScript
;
/*************************************************************************
*
* 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 });
/**
* Echo
* ---------
* return the request as the response
*
* @type {{name: string, description: string, title: string, defaults: {path: string}, fn: module.exports.fn}}
*/
class echo {
constructor() {
this.name = "api.echo";
this.title = "return the response";
}
fn(operation, _options) {
false && operation;
let context = operation.context;
let defaults = operation.feature.defaults || { now: Date.now(), echo: true };
return function (req, res) {
let payload = req.json || req.body || defaults;
if (req.method == "GET") {
payload = { path: req.path, url: req.url, params: req.params, query: req.query, headers: req.headers, now: Date.now() };
}
context.log({ code: "api:policy:echo", payload: payload, defaults: defaults });
res.status(200);
res.json(payload);
};
}
}
exports.default = echo;
;
//# sourceMappingURL=echo.js.map