/************************************************************************* * * Troven CONFIDENTIAL * __________________ * * (c) 2017-2020 Troven Ventures 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. */ import * as _ from "lodash"; import { IChassisFeature, IOperation } from "../interfaces"; /** * Echo * --------- * return the request as the response * * @type {{name: string, description: string, title: string, defaults: {path: string}, fn: module.exports.fn}} */ export default class echo implements IChassisFeature { name = "api.echo"; title = "return the response"; fn(operation: IOperation, _options: any): Function { false && operation; let context = operation.context; let defaults = _options.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:echo", payload: payload, typeof: typeof payload, defaults: defaults, }); res.status(200); res.json({ echo: payload, typeof: typeof payload }); }; } }