add adminapi dans tribe_dns.json

This commit is contained in:
2026-11-08 15:47:03 +01:00
parent 57df038a76
commit 39e8da1186
2 changed files with 55 additions and 17 deletions
+48 -10
View File
@@ -77,23 +77,38 @@ apxtri.main = async () => {
delete tribesdns[tribe];
}
});
if (!tribesdns.adminapi) {
tribesdns.adminapi = Array.isArray(conf.dns) ? conf.dns : [];
console.log(
"\x1b[31m restore missing adminapi entry in tribes_dns.json\x1b[0m"
);
}
// A partial/restored adminapi.json must not crash the whole server: fill
// the runtime configuration from the install template and warn loudly.
const initconf = fs.readJsonSync(
"../adminapi/apxtri/setup/initadminapi.json"
);
let confchanged = false;
if (!conf.api) {
conf.api = JSON.parse(JSON.stringify(initconf.api));
confchanged = true;
console.log(
"\x1b[31m adminapi.json is missing 'api', using defaults from apxtri/setup/initadminapi.json. Restore this file from a backup.\x1b[0m"
);
}
if (!conf.socket) {
conf.socket = JSON.parse(JSON.stringify(initconf.socket));
confchanged = true;
console.log(
"\x1b[31m adminapi.json is missing 'socket', using default port from apxtri/setup/initadminapi.json.\x1b[0m"
);
}
if (confchanged) {
fs.outputJSONSync(adminapipath, conf, { space: 2 });
console.log(
"\x1b[31m adminapi.json repaired on disk; check it and keep a backup.\x1b[0m"
);
}
//check if new tribe was add (only real tribe folders, never tmp/.git/...)
const tribedirs = glob
.sync("../*")
@@ -336,31 +351,54 @@ apxtri.runexpress = async (tribesdns, conf) => {
const checkRequestSafety = require(
path.resolve("./apxtri/middlewares/checkRequestSafety.js")
);
let tribeIds = Object.keys(tribesdns).filter((tribe) =>
apxtri.istribe(tribe)
);
if (!tribesdns.adminapi) {
tribesdns.adminapi = Array.isArray(conf.dns) ? conf.dns : [];
}
let tribeIds = [
...new Set([
"adminapi",
...Object.keys(tribesdns).filter((tribe) => apxtri.istribe(tribe)),
]),
];
// context is store in /itm/tribename.json ={contexte:{routes:[],models:[{model:,tplstringslg:[]}]}
// routes={url,route} check how to add plugin tribe route later
// keep only the 2 last part (.) of domain name to validate requests with it (generic domain)
let routes = [];
let doms = [];
tribeIds.forEach((t) => {
tribesdns[t].forEach((d) => {
const dnsentries = Array.isArray(tribesdns[t]) ? tribesdns[t] : [];
dnsentries.forEach((d) => {
const dm = d.split(".").slice(-2).join(".");
if (!doms.includes(dm)) doms.push(dm);
//reindex database attention check dev-ants/.. a bug was fixed
});
//reindex database once per tribe (not once per DNS entry)
glob.sync(`../${t}/objects/*`).forEach((o) => {
if (!fs.existsSync(o) || !fs.lstatSync(o).isDirectory()) return;
if (
!fs.existsSync(path.join(o, "itm")) &&
!fs.existsSync(path.join(o, "conf.json"))
) {
const confpath = path.join(o, "conf.json");
if (!fs.existsSync(confpath) || !fs.existsSync(path.join(o, "itm"))) {
return;
}
let objconf;
try {
objconf = fs.readJSONSync(confpath);
} catch (err) {
return;
}
if (!objconf || typeof objconf.schema !== "string" || !objconf.schema) {
return;
}
const schemapath = `../${
objconf.schema.endsWith(".json")
? objconf.schema
: `${objconf.schema}.json`
}`;
if (!fs.existsSync(schemapath)) {
console.log(`skip reindex ${o}: schema not found (${objconf.schema})`);
return;
}
console.log("reindex: ", o);
Odmdb.runidx(o);
});
});
const context = {};
const pathtr = path.resolve(`../${t}`);
context.routes = [];
+1 -1
View File
@@ -989,7 +989,7 @@ Odmdb.runidx = (objectPathname, schema) => {
if (!schema || !schema.apxid) {
const getschema = Odmdb.Schema(objectPathname, true);
if (getschema.status != 200) {
console.log(getschema)
if (log) console.log(getschema);
return getschema;
}
schema = getschema.data.schema;