add cam origin selector. fix wasm newpoly

This commit is contained in:
Stewart Allen 2025-07-10 16:54:02 -04:00
commit 5532cf28e4
12 changed files with 277 additions and 132 deletions

90
app.js
View file

@ -72,11 +72,6 @@ function init(mod) {
dversion = debug ? `_${version}` : version;
forceUseCache = ENV.cache ? true : false;
const approot = PATH.join("main","gapp");
const refcache = {};
const callstack = [];
let xxxx = false;
if (!ENV.electron) {
generateDevices();
}
@ -116,8 +111,6 @@ function init(mod) {
});
}
mod.add(rewriteHtmlVersion);
// example of how to use the new middleware
// mod.add(appendContent('/kiri/index.html', '<script>console.log("hello")</script>'));
mod.static("/lib/", "src");
mod.static("/obj/", "web/obj");
mod.static("/font/", "web/font");
@ -126,8 +119,8 @@ function init(mod) {
mod.static("/moto/", "web/moto");
mod.static("/kiri/", "web/kiri");
// module loader
function load_modules(root, force) {
// load modules
lastmod(`${dir}/${root}`) && fs.readdirSync(`${dir}/${root}`).forEach(mdir => {
const modpath = `${root}/${mdir}`;
if (dir.charAt(0) === '.' && !ENV.single) return;
@ -152,7 +145,7 @@ function init(mod) {
// load optional local modules
load_modules('mods');
// run loads injected by modules
// run load functions injected by modules
while (load.length) {
try {
load.shift()();
@ -161,7 +154,7 @@ function init(mod) {
}
}
// minify appends
// minify appends in production mode
if (!debug) {
for (let key of Object.keys(append)) {
append[key] = minify(append[key]);
@ -189,14 +182,14 @@ function initModule(mod, file, dir) {
// express functions added here show up at "/api/" url root
api: api,
adm: {
setver: (ver) => { oversion = ver },
crossOrigin: (bool) => { crossOrigin = bool }
setver(ver) { oversion = ver },
crossOrigin(bool) { crossOrigin = bool }
},
events,
const: {
args: {},
meta: mod.meta,
debug: debug,
debug,
moddir: dir,
rootdir: mod.dir,
version: oversion || version
@ -209,35 +202,21 @@ function initModule(mod, file, dir) {
},
mod: mods,
util: {
guid,
time,
log: logger.log,
time: time,
guid: guid,
logger: log.new,
mkdirs: util.mkdir,
isfile: util.isfile,
confdir: util.confdir,
datadir: util.datadir,
lastmod: lastmod,
obj2string: obj2string,
string2obj: string2obj,
isfile: util.isfile,
getCookieValue: cookieValue,
logger: log.new
},
inject: (code, file, opt = {}) => {
const path = mod.dir + '/' + dir + '/' + file;
try {
const body = fs.readFileSync(path);
// console.log({ inject: code, file, opt });
if (opt.first) {
append[code] = body.toString() + '\n' + append[code];
} else {
append[code] += body.toString() + '\n';
}
} catch (e) {
console.log({ missing_file: path, dir, mod });
}
obj2string(o) { return JSON.stringify(o) },
string2obj(s) { return JSON.parse(s) },
},
path: {
any: arg => { mod.add(arg) },
any(arg) { mod.add(arg) },
code() {
const [ path, file ] = [ ...arguments ];
if (lastmod(file)) {
@ -251,13 +230,13 @@ function initModule(mod, file, dir) {
console.log({ MISSING_CODE: path, file });
}
},
full: arg => { mod.add(fullpath(arg)) },
map: arg => { mod.add(fixedmap(arg)) },
pre: arg => { mod.add(prepath(arg)) },
full(arg) { mod.add(fullpath(arg)) },
map(arg) { mod.add(fixedmap(arg)) },
pre(arg) { mod.add(prepath(arg)) },
redir: redir,
remap: remap,
setup: fn => { setupFn = fn },
static: (root, pre) => {
setup(fn) { setupFn = fn },
static(root, pre) {
mod.static(pre || "/", root);
},
},
@ -271,22 +250,29 @@ function initModule(mod, file, dir) {
ws: {
register: mod.wss
},
onload: (fn) => {
inject(code, file, opt = {}) {
const path = mod.dir + '/' + dir + '/' + file;
try {
const body = fs.readFileSync(path);
// console.log({ inject: code, file, opt });
if (opt.first) {
append[code] = body.toString() + '\n' + append[code];
} else {
append[code] += body.toString() + '\n';
}
} catch (e) {
console.log({ missing_file: path, dir, mod });
}
},
onload(fn) {
load.push(fn);
},
onexit: (fn) => {
onexit(fn) {
mod.on.exit(fn);
}
});
}
// prevent caching of specified modules
const cachever = {};
function promise(resolve, reject) {
return new Promise(resolve, reject);
}
function rval() {
return (Math.round(Math.random()*0xffffffff)).toString(36);
}
@ -299,14 +285,6 @@ function time() {
return Date.now();
}
function obj2string(o) {
return JSON.stringify(o);
}
function string2obj(s) {
return JSON.parse(s);
}
function handleSetup(req, res, next) {
if (setupFn) {
setupFn(req, res, next);