modif setup

This commit is contained in:
philc 2024-12-02 17:24:21 +01:00
parent 029f942ecd
commit 70b1d5f5cb
2 changed files with 34 additions and 24 deletions

View File

@ -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,7 +191,8 @@ 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)
const nginxrestart =
inittribe.nginx && inittribe.nginx.restart
? inittribe.nginx.restart
: fs.readJSONSync("../adminapi/apxtri/setup/initadminapi.json").nginx
.restart;
@ -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));
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(express.json(conf.api.json));
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",

View File

@ -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"
}