Skip to content

Commit

Permalink
headless response as datat
Browse files Browse the repository at this point in the history
  • Loading branch information
btopro committed Oct 24, 2024
1 parent 21d1f54 commit afdc1a3
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,33 @@ 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}`
},
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");
Expand Down

0 comments on commit afdc1a3

Please sign in to comment.