diff --git a/app.js b/app.js index 7c151c95..cfa02a21 100644 --- a/app.js +++ b/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 }); diff --git a/src/geo/csg.js b/src/geo/csg.js index 0aec7c09..f49138d1 100644 --- a/src/geo/csg.js +++ b/src/geo/csg.js @@ -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; diff --git a/src/kiri/core/consts.js b/src/kiri/core/consts.js index 3b29af09..4bf52d4d 100644 --- a/src/kiri/core/consts.js +++ b/src/kiri/core/consts.js @@ -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'; diff --git a/src/kiri/core/init.js b/src/kiri/core/init.js index 1b96bfad..7b289ad1 100644 --- a/src/kiri/core/init.js +++ b/src/kiri/core/init.js @@ -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'; diff --git a/src/kiri/mode/cam/anim-3d-fe.js b/src/kiri/mode/cam/anim-3d-fe.js index 295e043e..3f31d97f 100644 --- a/src/kiri/mode/cam/anim-3d-fe.js +++ b/src/kiri/mode/cam/anim-3d-fe.js @@ -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 }); diff --git a/src/kiri/mode/cam/cl-stock.js b/src/kiri/mode/cam/cl-stock.js index 8d2e291e..dbb1777d 100644 --- a/src/kiri/mode/cam/cl-stock.js +++ b/src/kiri/mode/cam/cl-stock.js @@ -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, diff --git a/src/kiri/mode/cam/init-menu.js b/src/kiri/mode/cam/init-menu.js index 40faf9f7..60c1f61b 100644 --- a/src/kiri/mode/cam/init-menu.js +++ b/src/kiri/mode/cam/init-menu.js @@ -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:'',title:"transparency",class:"padleft"}), - anim.model = newButton(null,"anim.model",{icon:'',title:"show model"}), - anim.shade = newButton(null,"anim.stock",{icon:'',title:"stock box"}), + anim.trans = newButton(null,null,{icon:'',title:"transparency",class:"padleft"}), + anim.model = newButton(null,null,{icon:'',title:"show model"}), + anim.shade = newButton(null,null,{icon:'',title:"stock box"}), ]) }, diff --git a/src/main/mesh.js b/src/main/mesh.js index b1271a04..aaae2bee 100644 --- a/src/main/mesh.js +++ b/src/main/mesh.js @@ -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 }; diff --git a/web/kiri/index.css b/web/kiri/index.css index a1f75cbe..945cf0e2 100644 --- a/web/kiri/index.css +++ b/web/kiri/index.css @@ -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 { diff --git a/web/kiri/manifest.json b/web/kiri/manifest.json index 92a74d65..ce4522be 100644 --- a/web/kiri/manifest.json +++ b/web/kiri/manifest.json @@ -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" } ] } diff --git a/web/mesh/index.css b/web/mesh/index.css index 298d6bd7..0c3dc2b4 100644 --- a/web/mesh/index.css +++ b/web/mesh/index.css @@ -10,7 +10,7 @@ @font-face { font-family: 'Russo One'; - src: url('/moto/russo-one.ttf'); + src: url('../moto/russo-one.ttf'); } /** defaults */