From 70b1d5f5cba6e2cb39d567bc238efd963fa9ee41 Mon Sep 17 00:00:00 2001 From: philc Date: Mon, 2 Dec 2024 17:24:21 +0100 Subject: [PATCH] modif setup --- apxtri/apxtri.js | 54 ++++++++++++++++++++++++++++-------------------- package.json | 4 ++-- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/apxtri/apxtri.js b/apxtri/apxtri.js index f6b7246..d1bd7bf 100755 --- a/apxtri/apxtri.js +++ b/apxtri/apxtri.js @@ -39,7 +39,7 @@ apxtri.main = async () => { .forEach(async (t) => { const tribe = path.basename(t); //console.log(tribe); - if (![".",".."].includes(tribe) && !tribesdns[tribe]) { + if (![".", ".."].includes(tribe) && !tribesdns[tribe]) { await apxtri.setuptribe(tribe, conf); } }); @@ -101,6 +101,9 @@ apxtri.setuptribe = async (tribe, conf) => { } } else { console.log(`a new tribe called ${tribe} was detected`); + const adminapiconf = fs.readJSONSync( + "../adminapi/objects/tribes/itm/adminapi.json" + ); inittribe = { tribeId: tribe, townpath: __dirname.replace("/adminapi/apxtri", ""), @@ -109,6 +112,8 @@ apxtri.setuptribe = async (tribe, conf) => { nationId: conf.nationId, townId: conf.townId, activelog: [], + api: { port: adminapiconf.api.port }, + socket: { port: adminapiconf.socket.port }, }; } inittribe.sudoUser = process.env.USER; @@ -186,10 +191,11 @@ apxtri.setuptribe = async (tribe, conf) => { // this command is ran by the setup.sh // grep -q '^127.0.0.1 adminapx.adminapi' /etc/hosts || echo '127.0.0.1 adminapx.adminapi' | sudo tee -a /etc/hosts > /dev/null const ips = await apxtri.getip(); - const nginxrestart = (inittribe.nginx && inittribe.nginx.restart) - ? inittribe.nginx.restart - : fs.readJSONSync("../adminapi/apxtri/setup/initadminapi.json").nginx - .restart; + const nginxrestart = + inittribe.nginx && inittribe.nginx.restart + ? inittribe.nginx.restart + : fs.readJSONSync("../adminapi/apxtri/setup/initadminapi.json").nginx + .restart; const { exec } = require("child_process"); exec(nginxrestart, (error, stdout, stderr) => { if (error) { @@ -229,7 +235,7 @@ apxtri.runexpress = async (tribesdns, conf) => { const context = {}; const pathtr = path.resolve(`../${t}`); context.routes = []; - tribroutes = glob.sync(`${pathtr}/apxtri/routes/*.js`).map((f) => { + tribroutes = glob.sync(`${pathtr}/apxtri/routes/*.js`).map((f) => { const rt = `/${t}/${path.basename(f, ".js")}`; context.routes.push(rt); return { url: rt, route: f }; @@ -257,10 +263,12 @@ apxtri.runexpress = async (tribesdns, conf) => { app.set(p, conf.api.appset[p]); }); // To set depending of data form or get size to send - app.use(bodyParser.urlencoded(conf.api.bodyparse.urlencoded)); - app.use(bodyParser.json(conf.api.bodyparse.json)); - // To set depending of post put json data size to send - app.use(express.json(conf.api.json)); + tribeIds.forEach((t) => { + app.use(`/${t}`, bodyParser.urlencoded(conf.api.bodyparse.urlencoded)); + app.use(`/${t}`, bodyParser.json(conf.api.bodyparse.json)); + // To set depending of post put json data size to send + app.use(`/${t}`, express.json(conf.api.json)); + }); app.disable("x-powered-by"); // for security app.locals.tribeids = tribeIds; const currentmod = "apxtri"; @@ -279,11 +287,11 @@ apxtri.runexpress = async (tribesdns, conf) => { doms.forEach((d) => { regtxt += `|${d.replace(/\./g, "\\.")}`; }); - regtxt+=")$" -// let cor = false;whatwg-url + regtxt += ")$"; + // let cor = false;whatwg-url const regorigin = new RegExp(regtxt); app.use((req, res, next) => { - let cor=false + let cor = false; //console.log(req.headers) if (req.headers.origin == undefined) { //used for mobile access @@ -326,20 +334,22 @@ apxtri.runexpress = async (tribesdns, conf) => { const ips = await apxtri.getip(); app.listen(conf.api.port, () => { let webaccess = `/api/ waits request on port:${conf.api.port} `; - let localnet = "/etc/hosts for your local network:\n" - let publicnet ="/etc/hosts for internet network:\n" + let localnet = "/etc/hosts for your local network:\n"; + let publicnet = "/etc/hosts for internet network:\n"; conf.dns.forEach((u) => { //webaccess += `http://${u}/api/ `; - Object.keys(ips).forEach(ik=>{ - if (ik=="WANIP"){ - publicnet+= `${ips.WANIP} ${u} \n`; - }else{ - localnet+= `${ips[ik]} ${u} \n` + Object.keys(ips).forEach((ik) => { + if (ik == "WANIP") { + publicnet += `${ips.WANIP} ${u} \n`; + } else { + localnet += `${ips[ik]} ${u} \n`; } - }) + }); }); console.log( - `\x1b[42m\x1b[37m${webaccess} \nOpen in your browser http(s):// ${conf.dns.join(" ")} to manage this apXtri town. \nCheck your network conf \n${localnet} ${publicnet}\nMore in README's project.\nTo get support ask \x1b[0m\x1b[32m in discord https://discord.gg/jF7cAkZn ` + `\x1b[42m\x1b[37m${webaccess} \nOpen in your browser http(s):// ${conf.dns.join( + " " + )} to manage this apXtri town. \nCheck your network conf \n${localnet} ${publicnet}\nMore in README's project.\nTo get support ask \x1b[0m\x1b[32m in discord https://discord.gg/jF7cAkZn ` ); console.log( "\x1b[42m\x1b[37m \n", diff --git a/package.json b/package.json index 96834b2..18b2c07 100755 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "dependencies": { "apidoc": "^1.2.0", "async": "^3.2.0", - "axios": "^1.7.7", + "axios": "^1.7.8", "bcrypt": "^5.0.0", "cors": "^2.8.4", "dayjs": "^1.11.13", @@ -68,13 +68,13 @@ "jszip": "^3.10.1", "jwt-simple": "^0.5.6", "mustache": "^4.2.0", + "nodemailer": "^6.9.16", "openpgp": "^5.10.1", "path": "^0.12.7", "pm2": "^5.4.2", "readline-sync": "^1.4.10", "sharp": "^0.33.4", "smtp-client": "^0.4.0", - "nodemailer": "^6.9.16", "stripe": "^17.3.1", "uuid": "^11.0.2" }