1
0
forked from apxtri/apxtri

reindex auto on start

This commit is contained in:
philc 2024-08-07 08:02:47 +02:00
parent 57db217ee4
commit 53fad87b25
2 changed files with 34 additions and 26 deletions

View File

@ -7,14 +7,15 @@ const path = require("path");
const cors = require("cors");
const express = require("express");
const process = require("process");
const Odmdb = require("./models/Odmdb.js");
/*******************************************
SEE README.md to have a quick start
********************************************/
if (!fs.existsSync("/etc/nginx/nginx.conf")) {
setupdone=false;
console.log(
setupdone = false;
console.log(
"\x1b[31m Check documentation, nginx have to be installed on this server first, no /etc/nginx/nginx.conf available, install then rerun yarn command.");
}
if (!fs.existsSync("../../conf.json")) {
@ -35,32 +36,39 @@ let tribeIds = Object.keys(tribelist);
// 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 cors with it (generic domain)
let routes=[]
let routes = []
tribeIds.forEach((t) => {
tribelist[t].dns.forEach((d) => {
const dm = d.split(".").slice(-2).join(".");
if (!doms.includes(dm)) doms.push(dm);
//reindex database
if (t == "smatchit") {
glob.sync(`../../${t}/objects/*`).forEach(o => {
console.log(t, o)
Odmdb.runidx(o)
})
}
});
const context={};
const pathtr=path.resolve(`../../${t}`);
context.routes=[]
tribroutes=glob.sync(`${pathtr}/ap*/routes/*.js`).map(f=>{
const rt=`/${t}/${path.basename(f, ".js")}`
context.routes.push(rt)
return { url: rt, route: f };
const context = {};
const pathtr = path.resolve(`../../${t}`);
context.routes = []
tribroutes = glob.sync(`${pathtr}/ap*/routes/*.js`).map(f => {
const rt = `/${t}/${path.basename(f, ".js")}`
context.routes.push(rt)
return { url: rt, route: f };
});
context.models=glob.sync(`${pathtr}/ap*/models/*.js`).map(f=>{
const modname=`${path.basename(f, ".js")}`
context.models = glob.sync(`${pathtr}/ap*/models/*.js`).map(f => {
const modname = `${path.basename(f, ".js")}`
return {
model: modname,
tplstrings:glob.sync(`${pathtr}/objects/tplstrings/${modname}_*.json`).map(l=>path.basename(l,'.json').split("_")[1] )
}
model: modname,
tplstrings: glob.sync(`${pathtr}/objects/tplstrings/${modname}_*.json`).map(l => path.basename(l, '.json').split("_")[1])
}
})
const conft=`../../itm/${t}.json`
const ctx=fs.readJsonSync(conft)
ctx.context=context
fs.outputJSONSync(conft,ctx,{spaces:2});
routes=routes.concat(tribroutes);
const conft = `../../itm/${t}.json`
const ctx = fs.readJsonSync(conft)
ctx.context = context
fs.outputJSONSync(conft, ctx, { spaces: 2 });
routes = routes.concat(tribroutes);
});
const app = express();
// load express parameter from conf
@ -70,11 +78,11 @@ Object.keys(conf.api.appset).forEach((p) => {
// To set depending of data form or get size to send
app.use(bodyParser.urlencoded(conf.api.bodyparse.urlencoded));
// To set depending of post put json data size to send
app.use(express.json({limit:'10mb',type:'application/json',rawBody:true}));
app.use(express.json({ limit: '10mb', type: 'application/json', rawBody: true }));
app.use(bodyParser.json(conf.api.bodyparse.json));
app.disable("x-powered-by"); // for security
app.locals.tribeids = tribeIds;
if (log){
if (log) {
console.log(
currentmod,
" Allowed DOMs to access to this apxtri server:",
@ -82,7 +90,7 @@ if (log){
);
console.log(currentmod, " app.locals.tribeids", app.locals.tribeids);
}
// Cors management
// Cors management
let originlst = "test";
doms.forEach((d) => {
originlst += `|${d.replace(/\./g, "\\.")}`;
@ -102,7 +110,7 @@ app.use((req, res, next) => {
"request origin:",
req.headers.origin,
"testcors:",
cor, "headers allowed: [", conf.api.exposedHeaders.join(','),"] match with reg:", regtxt
cor, "headers allowed: [", conf.api.exposedHeaders.join(','), "] match with reg:", regtxt
);
cors({
origin: cor,

View File

@ -900,7 +900,7 @@ Odmdb.runidx = (objectPathname, schema) => {
});
Object.keys(ventil).forEach((n) => {
//if (log) console.log(currentmod,`${objectPathname}/idx/${ventil[n].name}.json`)
fs.outputJSON(
fs.outputJSONSync(
`${objectPathname}/idx/${ventil[n].name}.json`,
ventil[n].data
);