diff --git a/CHANGELOG.md b/CHANGELOG.md index 18507e64..90f01c2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - bug fixes - custom module / theme: prevent reloading the module while the file is being written to + - server: if a theme is used, attempt to resolve image urls against the theme file's location - modal/button: prevent error when `label` is updated - widgets diff --git a/src/server/server.js b/src/server/server.js index 45c5a301..0fb8de3c 100644 --- a/src/server/server.js +++ b/src/server/server.js @@ -38,6 +38,9 @@ if (settings.read('client-options')) { } } +var resolveDirs = theme.files.map(x=>path.dirname(x)) +resolveDirs = resolveDirs.filter((x, index)=>{return resolveDirs.indexOf(x) === index}) +resolveDirs.push('') // absolute function httpRoute(req, res) { @@ -91,20 +94,22 @@ function httpRoute(req, res) { url = url.replace(/^\/([^/]*:)/, '$1') // strip leading slash if (url.match(/.(svg|jpg|jpeg|png|apng|gif|webp|tiff|xbm|bmp|ico|ttf|otf|woff|woff2|html|css|js)(\?[0-9]*)?$/i)) { - try { - // relative resolution (to session path) - var id = urlparser.parse('?' + req.headers.cookie, true).query.client_id, - sessionPath = path.dirname(ipc.clients[id].sessionPath) - res.sendFile(path.resolve(sessionPath + url)) - } catch(e) { - // absolute resolution + // Resolution order: session path, theme path, absolute path + + var id = urlparser.parse('?' + req.headers.cookie, true).query.client_id, + sessionPath = path.dirname(ipc.clients[id].sessionPath) + + for (var i = -1; i < resolveDirs.length; i++) { + var p = i === -1 ? sessionPath : resolveDirs[i] try { - res.sendFile(path.resolve(url)) - } catch(e) { - console.error(`(ERROR, HTTP) File not found: ${url}`) - } + res.sendFile(path.resolve(p, url)) + return true + } catch(e) {} } + + console.error(`(ERROR, HTTP) File not found: ${url}`) + } else if (url.includes('/osc-ping')) { httpCheck(true) } else { diff --git a/src/server/theme.js b/src/server/theme.js index 263aa32b..3140d31a 100644 --- a/src/server/theme.js +++ b/src/server/theme.js @@ -36,7 +36,7 @@ class Theme { } } - if (!this.files.length) { + if (this.files.length) { this.watcher = chokidar.watch(this.files, {awaitWriteFinish: {stabilityThreshold: 200}}).on('change', ()=>{ if (!ipc) ipc = require('./server').ipc