add adminapi dans tribe_dns.json
This commit is contained in:
+54
-16
@@ -77,23 +77,38 @@ apxtri.main = async () => {
|
|||||||
delete tribesdns[tribe];
|
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
|
// A partial/restored adminapi.json must not crash the whole server: fill
|
||||||
// the runtime configuration from the install template and warn loudly.
|
// the runtime configuration from the install template and warn loudly.
|
||||||
const initconf = fs.readJsonSync(
|
const initconf = fs.readJsonSync(
|
||||||
"../adminapi/apxtri/setup/initadminapi.json"
|
"../adminapi/apxtri/setup/initadminapi.json"
|
||||||
);
|
);
|
||||||
|
let confchanged = false;
|
||||||
if (!conf.api) {
|
if (!conf.api) {
|
||||||
conf.api = JSON.parse(JSON.stringify(initconf.api));
|
conf.api = JSON.parse(JSON.stringify(initconf.api));
|
||||||
|
confchanged = true;
|
||||||
console.log(
|
console.log(
|
||||||
"\x1b[31m adminapi.json is missing 'api', using defaults from apxtri/setup/initadminapi.json. Restore this file from a backup.\x1b[0m"
|
"\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) {
|
if (!conf.socket) {
|
||||||
conf.socket = JSON.parse(JSON.stringify(initconf.socket));
|
conf.socket = JSON.parse(JSON.stringify(initconf.socket));
|
||||||
|
confchanged = true;
|
||||||
console.log(
|
console.log(
|
||||||
"\x1b[31m adminapi.json is missing 'socket', using default port from apxtri/setup/initadminapi.json.\x1b[0m"
|
"\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/...)
|
//check if new tribe was add (only real tribe folders, never tmp/.git/...)
|
||||||
const tribedirs = glob
|
const tribedirs = glob
|
||||||
.sync("../*")
|
.sync("../*")
|
||||||
@@ -336,30 +351,53 @@ apxtri.runexpress = async (tribesdns, conf) => {
|
|||||||
const checkRequestSafety = require(
|
const checkRequestSafety = require(
|
||||||
path.resolve("./apxtri/middlewares/checkRequestSafety.js")
|
path.resolve("./apxtri/middlewares/checkRequestSafety.js")
|
||||||
);
|
);
|
||||||
let tribeIds = Object.keys(tribesdns).filter((tribe) =>
|
if (!tribesdns.adminapi) {
|
||||||
apxtri.istribe(tribe)
|
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:[]}]}
|
// context is store in /itm/tribename.json ={contexte:{routes:[],models:[{model:,tplstringslg:[]}]}
|
||||||
// routes={url,route} check how to add plugin tribe route later
|
// 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)
|
// keep only the 2 last part (.) of domain name to validate requests with it (generic domain)
|
||||||
let routes = [];
|
let routes = [];
|
||||||
let doms = [];
|
let doms = [];
|
||||||
tribeIds.forEach((t) => {
|
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(".");
|
const dm = d.split(".").slice(-2).join(".");
|
||||||
if (!doms.includes(dm)) doms.push(dm);
|
if (!doms.includes(dm)) doms.push(dm);
|
||||||
//reindex database attention check dev-ants/.. a bug was fixed
|
});
|
||||||
glob.sync(`../${t}/objects/*`).forEach((o) => {
|
//reindex database once per tribe (not once per DNS entry)
|
||||||
if (!fs.existsSync(o) || !fs.lstatSync(o).isDirectory()) return;
|
glob.sync(`../${t}/objects/*`).forEach((o) => {
|
||||||
if (
|
if (!fs.existsSync(o) || !fs.lstatSync(o).isDirectory()) return;
|
||||||
!fs.existsSync(path.join(o, "itm")) &&
|
const confpath = path.join(o, "conf.json");
|
||||||
!fs.existsSync(path.join(o, "conf.json"))
|
if (!fs.existsSync(confpath) || !fs.existsSync(path.join(o, "itm"))) {
|
||||||
) {
|
return;
|
||||||
return;
|
}
|
||||||
}
|
let objconf;
|
||||||
console.log("reindex: ", o);
|
try {
|
||||||
Odmdb.runidx(o);
|
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 context = {};
|
||||||
const pathtr = path.resolve(`../${t}`);
|
const pathtr = path.resolve(`../${t}`);
|
||||||
|
|||||||
@@ -989,7 +989,7 @@ Odmdb.runidx = (objectPathname, schema) => {
|
|||||||
if (!schema || !schema.apxid) {
|
if (!schema || !schema.apxid) {
|
||||||
const getschema = Odmdb.Schema(objectPathname, true);
|
const getschema = Odmdb.Schema(objectPathname, true);
|
||||||
if (getschema.status != 200) {
|
if (getschema.status != 200) {
|
||||||
console.log(getschema)
|
if (log) console.log(getschema);
|
||||||
return getschema;
|
return getschema;
|
||||||
}
|
}
|
||||||
schema = getschema.data.schema;
|
schema = getschema.data.schema;
|
||||||
|
|||||||
Reference in New Issue
Block a user