allow app versions to be served with prefixes instead of cookies
This commit is contained in:
parent
e991b362e0
commit
a4e687f709
11 changed files with 55 additions and 28 deletions
42
app.js
42
app.js
|
|
@ -36,6 +36,7 @@ let http;
|
|||
let util;
|
||||
let dir;
|
||||
let log;
|
||||
let pre;
|
||||
|
||||
const EventEmitter = require('events');
|
||||
class AppEmitter extends EventEmitter {}
|
||||
|
|
@ -63,6 +64,7 @@ function init(mod) {
|
|||
startTime = time();
|
||||
lastmod = mod.util.lastmod;
|
||||
logger = mod.log;
|
||||
pre = ENV.pre || mod.meta.pre;
|
||||
debug = ENV.debug || mod.meta.debug;
|
||||
oversion = ENV.over || mod.meta.over;
|
||||
crossOrigin = ENV.xorigin || mod.meta.xorigin || false;
|
||||
|
|
@ -80,7 +82,19 @@ function init(mod) {
|
|||
generateDevices();
|
||||
}
|
||||
|
||||
if (pre) {
|
||||
for (let [k,v] of Object.entries(productionMap)) {
|
||||
productionMap[`${pre}${k}`] = `${pre}${v}`;
|
||||
}
|
||||
}
|
||||
|
||||
mod.on.test((req) => {
|
||||
if (req.app?.path?.startsWith(pre)) {
|
||||
req.url = req.url.substring(pre.length);
|
||||
req.app.path = req.app.path.substring(pre.length);
|
||||
req.app.ispre = true;
|
||||
return true;
|
||||
}
|
||||
let cookie = cookieValue(req.headers.cookie, "version") || '';
|
||||
let vmatch = mod.meta.version || "*";
|
||||
if (!Array.isArray(vmatch)) {
|
||||
|
|
@ -108,12 +122,12 @@ function init(mod) {
|
|||
mod.add(serveWasm);
|
||||
mod.add(serveCode);
|
||||
mod.add(fullpath({
|
||||
"/kiri" : redir("/kiri/", 301),
|
||||
"/mesh" : redir("/mesh/", 301),
|
||||
"/meta" : redir("/meta/", 301),
|
||||
"/kiri/index.html" : redir("/kiri/", 301),
|
||||
"/mesh/index.html" : redir("/mesh/", 301),
|
||||
"/meta/index.html" : redir("/meta/", 301)
|
||||
"/kiri" : redir((pre??"") + "/kiri/", 301),
|
||||
"/mesh" : redir((pre??"") + "/mesh/", 301),
|
||||
"/meta" : redir((pre??"") + "/meta/", 301),
|
||||
"/kiri/index.html" : redir((pre??"") + "/kiri/", 301),
|
||||
"/mesh/index.html" : redir((pre??"") + "/mesh/", 301),
|
||||
"/meta/index.html" : redir((pre??"") + "/meta/", 301)
|
||||
}));
|
||||
mod.add(handleVersion);
|
||||
mod.add(fixedmap("/api/", api));
|
||||
|
|
@ -318,16 +332,21 @@ const productionMap = {
|
|||
'/lib/kiri/run/engine.js' : '/lib/pack/kiri-eng.js',
|
||||
'/lib/kiri/run/minion.js' : '/lib/pack/kiri-pool.js',
|
||||
'/lib/kiri/run/worker.js' : '/lib/pack/kiri-work.js',
|
||||
// '/lib/kiri/run/frame.js' : '/lib/pack/kiri-frame.js',
|
||||
};
|
||||
|
||||
const redirList = [
|
||||
"/kiri/",
|
||||
"/mesh/"
|
||||
];
|
||||
|
||||
function handleVersion(req, res, next) {
|
||||
let vstr = oversion || dversion || version;
|
||||
if (["/kiri/","/mesh/"].indexOf(req.app.path) >= 0 && req.url.indexOf(vstr) < 0) {
|
||||
if (!redirList.indexOf(req.app.path) >= 0 && req.url.indexOf(vstr) < 0) {
|
||||
let pp = req.app.ispre ? pre : undefined;
|
||||
if (req.url.indexOf("?") > 0) {
|
||||
return http.redirect(res, `${req.url},ver:${vstr}`);
|
||||
return http.redirect(res, `${pp??''}${req.url},ver:${vstr}`);
|
||||
} else {
|
||||
return http.redirect(res, `${req.url}?ver:${vstr}`);
|
||||
return http.redirect(res, `${pp??''}${req.url}?ver:${vstr}`);
|
||||
}
|
||||
} else if (!debug) {
|
||||
// in production serve packed bundles
|
||||
|
|
@ -546,7 +565,8 @@ function rewriteHtmlVersion(req, res, next) {
|
|||
"/lib/main/mesh.js"
|
||||
].indexOf(req.app.path) >= 0) {
|
||||
addCorsHeaders(req, res);
|
||||
const data = append[req.app.path.split('/')[3].split('.')[0]];
|
||||
// const data = append[req.app.path.split('/')[3].split('.')[0]];
|
||||
const data = append[req.app.path.split('.')[0].split('/').pop()];
|
||||
|
||||
if (!data) return next();
|
||||
if (debug) logger.log({ append: req.app.path, data: data.length });
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ function indexVertices(pos) {
|
|||
|
||||
let Instance;
|
||||
manifold({
|
||||
locateFile() { return "/wasm/manifold.wasm" }
|
||||
locateFile() { return "../wasm/manifold.wasm" }
|
||||
}).then(inst => {
|
||||
inst.setup();
|
||||
Instance = inst;
|
||||
|
|
|
|||
|
|
@ -142,8 +142,8 @@ const PMODES = {
|
|||
};
|
||||
|
||||
const PATHS = {
|
||||
work: "/lib/kiri/run/worker.js",
|
||||
pool: "/lib/kiri/run/minion.js"
|
||||
work: "../lib/kiri/run/worker.js",
|
||||
pool: "./minion.js"
|
||||
};
|
||||
|
||||
const SEED = 'kiri-seed';
|
||||
|
|
|
|||
|
|
@ -1802,8 +1802,12 @@ function init_two() {
|
|||
sdb.kiri_beta = beta;
|
||||
}
|
||||
|
||||
// hide url params
|
||||
history.replaceState({}, '', '/kiri/');
|
||||
// hide url params but preserve version root (when present)
|
||||
let wlp = WIN.location.pathname;
|
||||
let kio = wlp.indexOf('/kiri/');
|
||||
if (kio >= 0) {
|
||||
history.replaceState({}, '', wlp.substring(0,kio + 6));
|
||||
}
|
||||
|
||||
// lift curtain
|
||||
$('curtain').style.display = 'none';
|
||||
|
|
|
|||
|
|
@ -87,10 +87,10 @@ Object.assign(client, {
|
|||
|
||||
animate_setup2(settings, ondone) {
|
||||
color = settings.controller.dark ? 0x888888 : 0;
|
||||
material = new THREE.MeshMatcapMaterial({
|
||||
material = new THREE.MeshPhongMaterial({
|
||||
flatShading: true,
|
||||
transparent: false,
|
||||
opacity: 0.9,
|
||||
opacity: 0.5,
|
||||
color: 0x888888,
|
||||
side: THREE.DoubleSide
|
||||
});
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ export function updateStock() {
|
|||
});
|
||||
env.camStock = new THREE.Mesh(geo, mat);
|
||||
env.camStock.renderOrder = 2;
|
||||
|
||||
let lo = 0.5;
|
||||
let lidat = [
|
||||
lo, lo, lo, lo, lo, -lo,
|
||||
|
|
|
|||
|
|
@ -55,9 +55,9 @@ export function menu() {
|
|||
anim.vala = newValue(6, {class:"center hide"}),
|
||||
anim.labpro = newLabel("%", {class:"padleft"}),
|
||||
anim.progress = newValue(5, {class:"center"}),
|
||||
anim.trans = newButton(null,"anim.trans",{icon:'<i class="fa-solid fa-border-none"></i>',title:"transparency",class:"padleft"}),
|
||||
anim.model = newButton(null,"anim.model",{icon:'<i class="fa-solid fa-eye"></i>',title:"show model"}),
|
||||
anim.shade = newButton(null,"anim.stock",{icon:'<i class="fa-solid fa-cube"></i>',title:"stock box"}),
|
||||
anim.trans = newButton(null,null,{icon:'<i class="fa-solid fa-border-none"></i>',title:"transparency",class:"padleft"}),
|
||||
anim.model = newButton(null,null,{icon:'<i class="fa-solid fa-eye"></i>',title:"show model"}),
|
||||
anim.shade = newButton(null,null,{icon:'<i class="fa-solid fa-cube"></i>',title:"stock box"}),
|
||||
])
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ function init() {
|
|||
motoClient.on('ready', restore_space);
|
||||
|
||||
// start worker
|
||||
motoClient.start('/lib/mesh/work.js?' + version);
|
||||
motoClient.start('../lib/mesh/work.js?' + version);
|
||||
|
||||
// trigger space event binding
|
||||
call.space_init({ space: space, platform });
|
||||
|
|
@ -91,7 +91,11 @@ function init() {
|
|||
call.ui_build();
|
||||
|
||||
// hide url params
|
||||
history.replaceState({}, '', '/mesh/');
|
||||
let wlp = window.location.pathname;
|
||||
let mio = wlp.indexOf('/mesh/');
|
||||
if (mio >= 0) {
|
||||
history.replaceState({}, '', wlp.substring(0,mio + 6));
|
||||
}
|
||||
|
||||
// for electron
|
||||
self.mesh = { api };
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
/* surface size configuration and font import */
|
||||
@font-face {
|
||||
font-family: 'Russo One';
|
||||
src: url('/moto/russo-one.ttf');
|
||||
src: url('../moto/russo-one.ttf');
|
||||
}
|
||||
@media only screen and (max-width : 1000px) {
|
||||
.top-menu > span > label {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
"background_color": "#ffffff",
|
||||
"orientation": "landscape-primary",
|
||||
"icons": [
|
||||
{ "src": "/kiri/logo-cube-512.png", "type": "image/png", "sizes": "512x512" },
|
||||
{ "src": "/kiri/logo-cube-144.png", "type": "image/png", "sizes": "144x144" }
|
||||
{ "src": "./logo-cube-512.png", "type": "image/png", "sizes": "512x512" },
|
||||
{ "src": "./logo-cube-144.png", "type": "image/png", "sizes": "144x144" }
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
@font-face {
|
||||
font-family: 'Russo One';
|
||||
src: url('/moto/russo-one.ttf');
|
||||
src: url('../moto/russo-one.ttf');
|
||||
}
|
||||
|
||||
/** defaults */
|
||||
|
|
|
|||
Loading…
Reference in a new issue