update nginx conf

This commit is contained in:
philc 2024-11-02 13:58:24 +01:00
parent d71a381120
commit 74ce5f0424
3 changed files with 21 additions and 68 deletions

View File

@ -62,7 +62,7 @@ apxtri.setup = async () => {
} }
return network 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( const initadminapi = fs.readJsonSync(
"../adminapi/apxtri/setup/initadminapi.json" "../adminapi/apxtri/setup/initadminapi.json"
); );
@ -71,56 +71,11 @@ apxtri.setup = async () => {
const townnation = initadminapi.townpath.split("/").slice(-1)[0].split("-"); const townnation = initadminapi.townpath.split("/").slice(-1)[0].split("-");
initadminapi.townId = townnation[0]; initadminapi.townId = townnation[0];
initadminapi.nationId = townnation[1]; initadminapi.nationId = townnation[1];
initadminapi.dns.push(`${initadminapi.townId}.${initadminapi.nationId}`);
} catch (err) { } catch (err) {
console.log("Your town folder must be something townid-nation"); console.log("Your town folder must be something townid-nation");
} }
initadminapi.sudoUser = process.env.USER; 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 //check nation exist and town does not exist
if ( if (
!fs.existsSync("../adminapi/objects/nations/idx/lst_nations.json") || !fs.existsSync("../adminapi/objects/nations/idx/lst_nations.json") ||
@ -176,7 +131,7 @@ apxtri.setup = async () => {
"../adminapi/apxtri/setup/nginx.wwwscf", "../adminapi/apxtri/setup/nginx.wwwscf",
"utf8" "utf8"
); );
initadminapi.website="adminapx"; initadminapi.website=initadminapi.dns.join(" ");
fs.outputFileSync( fs.outputFileSync(
`../adminapi/nginx/adminapx.adminapi.conf`, `../adminapi/nginx/adminapx.adminapi.conf`,
Mustache.render(nginxapx, initadminapi) Mustache.render(nginxapx, initadminapi)
@ -191,8 +146,9 @@ apxtri.setup = async () => {
console.log("\x1b[42m", error, stdout, stderr, "x1b[0m"); console.log("\x1b[42m", error, stdout, stderr, "x1b[0m");
process.exit(0); process.exit(0);
} else { } else {
const etchosts=Object.values(ips).map(ip => `${ip} ${initadminapi.website}`).join('\n ')
console.log( 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); if (!doms.includes(dm)) doms.push(dm);
//reindex database attention check dev-ants/.. a bug was fixed //reindex database attention check dev-ants/.. a bug was fixed
glob.sync(`../${t}/objects/*`).forEach((o) => { glob.sync(`../${t}/objects/*`).forEach((o) => {
console.log(t, o); console.log("reindex: ", o);
Odmdb.runidx(o); Odmdb.runidx(o);
}); });
}); });
@ -237,8 +193,8 @@ apxtri.runexpress = async (tribesdns, conf) => {
.map((l) => path.basename(l, ".json").split("_")[1]), .map((l) => path.basename(l, ".json").split("_")[1]),
}; };
}); });
console.log(context.routes); //console.log(context.routes);
console.log(context.models); //console.log(context.models);
//const conft = `../itm/${t}.json`; //const conft = `../itm/${t}.json`;
//const ctx = fs.readJsonSync(conft); //const ctx = fs.readJsonSync(conft);
//ctx.context = context; //ctx.context = context;
@ -311,25 +267,23 @@ apxtri.runexpress = async (tribesdns, conf) => {
}); });
if (log) { if (log) {
console.log(currentmod, logroute); console.log(currentmod, logroute);
if (process.env.NODE_MODE == "dev") console.log(currentmod,conf.api);
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`
);
} }
//Listen event file for each tribe //Listen event file for each tribe
// @TODO à ajouter ici // @TODO à ajouter ici
app.listen(conf.api.port, () => { 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) => { conf.dns.forEach((u) => {
webaccess += `${u}/api/ `; webaccess += `http://${u}/api/ `;
}); });
if (log) console.log(currentmod, webaccess); console.log(currentmod, webaccess);
}); });
console.log( console.log(
"\x1b[42m\x1b[37m", `\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 `
"Made with love for people's freedom, enjoy !!!", );
console.log(
"\x1b[42m\x1b[37m \n",
" Made with love for people's freedom, enjoy !!! ",
"\x1b[0m" "\x1b[0m"
); );
}; };

View File

@ -1,14 +1,13 @@
{ {
"tribeId": "adminapi", "tribeId": "adminapi",
"urlinit":["http://apx.adminapi","https://testwall-ants.ndda.fr"],
"idxname":{"towns":"towns","nation":"nations","pagans":"alias"}, "idxname":{"towns":"towns","nation":"nations","pagans":"alias"},
"dns": [ "dns": [
"adminapx.adminapi" "adminapx.adminapi"
], ],
"status": "unchain", "status": "unchain",
"nationId": "ants", "nationId": "",
"townId": "newdev", "townId": "",
"sudoUser": "phil", "sudoUser": "",
"api": { "api": {
"port": 3021, "port": 3021,
"activelog": [], "activelog": [],

View File

@ -1,5 +1,5 @@
server { server {
server_name {{{website}}}.{{{tribeId}}}; server_name {{{website}}};
add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Credentials' 'true' always; add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always; add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;