From 74ce5f042441cc20ef966c2376ef2535c2ebef24 Mon Sep 17 00:00:00 2001 From: philc Date: Sat, 2 Nov 2024 13:58:24 +0100 Subject: [PATCH] update nginx conf --- apxtri/apxtri.js | 80 ++++++++-------------------------- apxtri/setup/initadminapi.json | 7 ++- apxtri/setup/nginx.wwwscf | 2 +- 3 files changed, 21 insertions(+), 68 deletions(-) diff --git a/apxtri/apxtri.js b/apxtri/apxtri.js index 7d15ad1..a131c23 100755 --- a/apxtri/apxtri.js +++ b/apxtri/apxtri.js @@ -62,7 +62,7 @@ apxtri.setup = async () => { } return network }; - console.log("Warning, this is a first install"); + console.log("Nice to meet you, this is a first install hope you'll enjoy, if any issues please request on discord https://discord.gg/jF7cAkZn"); const initadminapi = fs.readJsonSync( "../adminapi/apxtri/setup/initadminapi.json" ); @@ -71,56 +71,11 @@ apxtri.setup = async () => { const townnation = initadminapi.townpath.split("/").slice(-1)[0].split("-"); initadminapi.townId = townnation[0]; initadminapi.nationId = townnation[1]; + initadminapi.dns.push(`${initadminapi.townId}.${initadminapi.nationId}`); } catch (err) { console.log("Your town folder must be something townid-nation"); } initadminapi.sudoUser = process.env.USER; - // Loop in initadminapi.urlinit until one answer - /*const headers = { - xtrkversion: 1, - xtribe: "adminapi", - xapp: "apx", - xlang: "fr", - xalias: "anonymous", - xhash: "anonymous", - xdays: 0, - xuuid: "0", - }; - // add in crontab each day - // find /home/phil/apxtowns/dev-ants/adminapi/objects -type d -name "nations" -o -name "towns" -o -name "pagans" -o -name "tplstring" -o -name "wwws" | tar -cvzf /home/phil/dev-ants/adminapi/objects/wwws/cdn/share/setupobjects.tar.gz - for (url of initadminapi.urlinit) { - if (!fs.existsSync("../objects/nations")) { - const urlinit = `${url}/api/adminapi/wwws/updatelocaldbanonymous/adminapi/apx/blockchain/0`; - const getdata = await fetch(urlinit, { headers: headers }); - console.log(getdata) - if (getdata.ok) { { - "name": "tribes_dns", - "keyval": "tribeId", - "type": "view", - "objkey": [ - "dns" - ], - "filter": "" - } - const data = await getdata.json(); - console.log(Object.keys(data.data.itms)); - Object.keys(data.data.itms).forEach((o) => { - //idxname contain the real name of the index to use - fs.outputJSONSync( - `../objects/${o}/idx/${initadminapi.idxname[o]}s.json`, - data.data.itms[o] - ); - // save each itm to init data - Object.keys(data.data.itms[o]).forEach((i) => { - fs.outputJSONSync( - `../objects/${o}/itms/${i}.json`, - data.data.itms[o][i] - ); - }); - }); - } - } - }*/ //check nation exist and town does not exist if ( !fs.existsSync("../adminapi/objects/nations/idx/lst_nations.json") || @@ -176,7 +131,7 @@ apxtri.setup = async () => { "../adminapi/apxtri/setup/nginx.wwwscf", "utf8" ); - initadminapi.website="adminapx"; + initadminapi.website=initadminapi.dns.join(" "); fs.outputFileSync( `../adminapi/nginx/adminapx.adminapi.conf`, Mustache.render(nginxapx, initadminapi) @@ -191,8 +146,9 @@ apxtri.setup = async () => { console.log("\x1b[42m", error, stdout, stderr, "x1b[0m"); process.exit(0); } else { + const etchosts=Object.values(ips).map(ip => `${ip} ${initadminapi.website}`).join('\n ') console.log( - `\x1b[42m#############################################################################################\x1b[0m\n\x1b[42mWellcome into this fresh apxtri install, this run as "yarn dev" to set up your machine with a public domain name.\n If this install is to be use accross internet or local network : add on yopur local machine in /etc/hosts lines:\n ${Object.values(ips).map(ip => `${ip} adminapx.adminapi`).join('\n')} \n then open in your local browser \x1b[0m\x1b[32mhttp://adminapx.adminapi\x1b[0m \x1b[42m \n In local dev continue with 'yarn dev'\nTo run as a production run 'yarn startapx' or 'yarn restartapx' this will use pm2 as production monitoring\n\x1b[0m\n\x1b[42m###########################################################################################\x1b[0m` + `\x1b[42m###############################################################################################################\x1b[0m\n\x1b[42mWellcome into this fresh apxtri install, currently running as "$ yarn dev".\n To access and set up a public domain name, add lines in file /etc/hosts into the machine you want to use to access:\n ${etchosts} \n Then open in your local browser \x1b[0m\x1b[32m http://${initadminapi.website} \x1b[0m \x1b[42m \nFor local dev continue with 'yarn dev'\nTo run as a production run 'yarn startapx' or 'yarn restartapx' then pm2 monitor your production process.\n\x1b[0m\n\x1b[42m###############################################################################################################\x1b[0m` ); } }); @@ -216,7 +172,7 @@ apxtri.runexpress = async (tribesdns, conf) => { if (!doms.includes(dm)) doms.push(dm); //reindex database attention check dev-ants/.. a bug was fixed glob.sync(`../${t}/objects/*`).forEach((o) => { - console.log(t, o); + console.log("reindex: ", o); Odmdb.runidx(o); }); }); @@ -237,8 +193,8 @@ apxtri.runexpress = async (tribesdns, conf) => { .map((l) => path.basename(l, ".json").split("_")[1]), }; }); - console.log(context.routes); - console.log(context.models); + //console.log(context.routes); + //console.log(context.models); //const conft = `../itm/${t}.json`; //const ctx = fs.readJsonSync(conft); //ctx.context = context; @@ -311,25 +267,23 @@ apxtri.runexpress = async (tribesdns, conf) => { }); if (log) { console.log(currentmod, logroute); - if (process.env.NODE_MODE == "dev") - console.log( - `\x1b[42m############################################################################################\x1b[0m\n\x1b[42mThis is dev conf accessible in http://dev-ants to switch this as production, you must run:\n 1 - 'yarn dev nationId:ants townId:dev dns:dev-ants' to conf your town and check it.\n 2 - 'yarn startpm2'\n Where:\n\x1b[42m * nationId have to exist in the nationchains\n * townId new or if exist must have the same current dns,\n * dns domaine that has to redirect 80/443 into this server.\n Check README's project to learn more.\x1b[0m\n To work with apxweb for the front use http://dev-ants/apxwebapp/www/websitename/src/index.html to use the api during dev process\n\x1b[42m############################################################################################\x1b[0m` - ); + console.log(currentmod,conf.api); } - //Listen event file for each tribe // @TODO à ajouter ici - app.listen(conf.api.port, () => { - let webaccess = `api waits request on port:${conf.api.port} for`; + let webaccess = `api waits request on port:${conf.api.port} for `; conf.dns.forEach((u) => { - webaccess += `${u}/api/ `; + webaccess += `http://${u}/api/ `; }); - if (log) console.log(currentmod, webaccess); + console.log(currentmod, webaccess); }); console.log( - "\x1b[42m\x1b[37m", - "Made with love for people's freedom, enjoy !!!", + `\x1b[42mOpen in your browser http://${conf.townId}.${conf.nationId} to manage this apXtri town. \nCheck that your local machine have in /etc/hosts \n127.0.0.1 ${conf.townId}.${conf.nationId} or WANIP ${conf.townId}.${conf.nationId} \nCheck README's project to learn more.\nTo get support \x1b[0m\x1b[32mask in discord https://discord.gg/jF7cAkZn ` + ); + console.log( + "\x1b[42m\x1b[37m \n", + " Made with love for people's freedom, enjoy !!! ", "\x1b[0m" ); }; diff --git a/apxtri/setup/initadminapi.json b/apxtri/setup/initadminapi.json index fa773c3..d1b02bc 100644 --- a/apxtri/setup/initadminapi.json +++ b/apxtri/setup/initadminapi.json @@ -1,14 +1,13 @@ { "tribeId": "adminapi", - "urlinit":["http://apx.adminapi","https://testwall-ants.ndda.fr"], "idxname":{"towns":"towns","nation":"nations","pagans":"alias"}, "dns": [ "adminapx.adminapi" ], "status": "unchain", - "nationId": "ants", - "townId": "newdev", - "sudoUser": "phil", + "nationId": "", + "townId": "", + "sudoUser": "", "api": { "port": 3021, "activelog": [], diff --git a/apxtri/setup/nginx.wwwscf b/apxtri/setup/nginx.wwwscf index 53c6933..143167e 100644 --- a/apxtri/setup/nginx.wwwscf +++ b/apxtri/setup/nginx.wwwscf @@ -1,5 +1,5 @@ server { -server_name {{{website}}}.{{{tribeId}}}; +server_name {{{website}}}; add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Credentials' 'true' always; add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;