From afdc1a316a93cd06499c551112595b0ed4cd02b5 Mon Sep 17 00:00:00 2001 From: btopro Date: Thu, 24 Oct 2024 12:47:39 -0400 Subject: [PATCH] headless response as datat --- src/cli.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/cli.js b/src/cli.js index e8bb654..2e5e79f 100644 --- a/src/cli.js +++ b/src/cli.js @@ -62,8 +62,19 @@ for (var method in RoutesMap) { } } +// fake response clas so we can capture the response from the headless route as opposed to print to console +class Res { + constructor() { + this.query = {}; + this.data = null; + } + send(data) { + this.data = data; + } +} + // method to bridge api calls in similar manner given a site already loaded into scope -export function cliBridge(op, body = {}) { +export async function cliBridge(op, body = {}) { let req = { route: { path: `${HAXCMS.basePath}${HAXCMS.systemRequestBase}${route}` @@ -71,14 +82,13 @@ export function cliBridge(op, body = {}) { body: body, method: "post" }; - let res = { - query: {}, - send: (data) => console.log(data), - }; + + let res = new Res(); const rMethod = req.method.toLowerCase(); if (HAXCMS.validateJWT(req, res)) { // call the method - RoutesMap.RoutesMap[rMethod][op](req, res); + await RoutesMap.RoutesMap[rMethod][op](req, res); + return {req: req, res: res}; } else { console.error("route connection issue");