Skip to content

Commit

Permalink
https://github.com/haxtheweb/issues/issues/2170
Browse files Browse the repository at this point in the history
  • Loading branch information
btopro committed Oct 16, 2024
1 parent a417254 commit d3f1ecc
Show file tree
Hide file tree
Showing 41 changed files with 650 additions and 60 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"dev": "nodemon src/app.js",
"start": "open http://localhost:3000 && npm run dev HAXCMS_DISABLE_JWT_CHECKS",
"build": "rm -rf dist && babel src --out-dir dist --copy-files --include-dotfiles && chmod 774 dist/local.js && chmod 774 dist/app.js && chmod 774 dist/cli.js",
"release": "npm run build && commit-and-tag-version && git push --follow-tags origin main && npm publish"
"release": "npm run build && commit-and-tag-version && git push --follow-tags origin main && npm publish",
"haxcms-nodejs-cli": "haxcms-nodejs-cli"
},
"repository": {
"type": "git",
Expand Down
86 changes: 40 additions & 46 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,27 @@
process.env.haxcms_middleware = "node-cli";
// HAXcms core settings
const { HAXCMS } = require('./lib/HAXCMS.js');
/**
* @todo need a configuration resolver of some kind
* if we are invoking stand alone, it'll need to install haxcms in place
* if it's in an existing HAXcms deploy, it should read off that _config / other multi-site directories
* if it's a HAXSite then it needs to supply config that works relative to that one
* This also influnces the entry index.html file
*/

const RoutesMap = require('./lib/RoutesMap.js');

// process arguments from commandline appropriately
const args = process.argv;
args.shift();
args.shift();
let body = {};
let cliOp = 'listCalls';
// 1st 2 args call the program itself
for (var i in args) {
let arg = args[i].split('=');
let param = arg[0].replace('--','');
let value = arg[1];
switch (param) {
case 'op':
cliOp = value;
break;
case "nodeTitle":
body.node = body.node || {};
body.node.title = value;
break;
case "site":
body.site = {
name: value
};
break;
// set everything else as parameters
default:
body[param] = value;
break;
}
}
let cliOp = null;
const cli = {
post: (path, callback) => callback({
route: {
path: path
post: (path, callback) =>
callback(
{
route: {
path: path
},
body: body,
method: "post"
},
body: body,
method: "post"
},
{
query: {},
send: (data) => console.log(data),
}),
{
query: {},
send: (data) => console.log(data),
}
),
get: (path, callback) => callback({
route: {
path: path
Expand Down Expand Up @@ -91,4 +60,29 @@ for (var method in RoutesMap) {
});
}
}
}
}

// method to bridge api calls in similar manner given a site already loaded into scope
export 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),
};
const rMethod = req.method.toLowerCase();
if (HAXCMS.validateJWT(req, res)) {
// call the method
RoutesMap.RoutesMap[rMethod][op](req, res);
}
else {
console.error("route connection issue");
}
}

export { cli };

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d3f1ecc

Please sign in to comment.