diff --git a/CHANGELOG.md b/CHANGELOG.md index a3f6172d..efe173b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ Version 2.0.0 server provided the session can be resumed. - Added support for having multiple Factorio installs and selecting which version to use on a per instance basis. +- Added config to specify which path the master interface is accessed under, + allowing it to be proxied behind web-server. ### Changes diff --git a/lib/config/definitions.js b/lib/config/definitions.js index 576c7085..95f3f737 100644 --- a/lib/config/definitions.js +++ b/lib/config/definitions.js @@ -42,6 +42,13 @@ MasterGroup.define({ optional: true, initial_value: 8443, }); +MasterGroup.define({ + name: "web_root", + title: "Web Root", + description: "Sub-path to where the web interface is hosted. Needed when proxying the web interface.", + type: "string", + initial_value: "/", +}); MasterGroup.define({ name: "tls_certificate", title: "TLS Certificate", diff --git a/master.js b/master.js index 5bbb2f20..977f391b 100644 --- a/master.js +++ b/master.js @@ -72,6 +72,7 @@ app.set('views', ['views', 'plugins']); // give ejs access to some interesting information app.use(function(req, res, next){ + res.locals.root = masterConfig.get("master.web_root"); res.locals.res = res; res.locals.req = req; res.locals.masterPlugins = masterPlugins; diff --git a/plugins/subspace_storage/master.js b/plugins/subspace_storage/master.js index f2ce2d35..3170af23 100644 --- a/plugins/subspace_storage/master.js +++ b/plugins/subspace_storage/master.js @@ -30,12 +30,13 @@ const masterInventoryGauge = new prometheus.Gauge( class MasterPlugin extends plugin.BaseMasterPlugin { async init() { + let root = this.master.config.get("master.web_root"); this.ui = { sidebar: [ { getHtml: () => ` `, }, ], diff --git a/plugins/subspace_storage/static/storage.js b/plugins/subspace_storage/static/storage.js index 9a99819d..b65326ae 100644 --- a/plugins/subspace_storage/static/storage.js +++ b/plugins/subspace_storage/static/storage.js @@ -62,7 +62,7 @@ function updateInventory() { drawcontents(data); } } - xmlhttp.open("GET", "/api/inventory", true); + xmlhttp.open("GET", `${root}api/inventory`, true); xmlhttp.send(); } if(JSON.parse(localStorage.settings)["Periodically update storage screen"]) { diff --git a/plugins/subspace_storage/views/storage.ejs b/plugins/subspace_storage/views/storage.ejs index da151dd7..f084cac4 100644 --- a/plugins/subspace_storage/views/storage.ejs +++ b/plugins/subspace_storage/views/storage.ejs @@ -1,7 +1,7 @@ <%- include("head") %> - + diff --git a/static/main.js b/static/main.js index deceacfe..a3330fbe 100644 --- a/static/main.js +++ b/static/main.js @@ -198,7 +198,7 @@ function getImageFromName(name){ return "https://wiki.factorio.com/images/" + capitalizeFirstLetter(replaceAll(factorioLocale["fluid-name"][name], ' ', '_').toLowerCase()) + ".png"; } else if(factorioLocale["equipment-name"] && factorioLocale["equipment-name"][name]){ return "https://wiki.factorio.com/images/" + capitalizeFirstLetter(replaceAll(factorioLocale["equipment-name"][name], ' ', '_').toLowerCase()) + ".png"; - } else return "/pictures/unknown-item.png"; + } else return `${root}pictures/unknown-item.png`; } window.factorioLocale = {}; $.getJSON("/api/getFactorioLocale", (locale) => { @@ -252,6 +252,6 @@ var imagelinks = { "battery-mk2-equipment": "/pictures/Battery_MK2.png", "personal-roboport-mk2-equipment": "/pictures/Personal_roboport_MK2.png", } -var populateImageLinks = async () => (await getJSON("/api/getPictures")).forEach(img => imagelinks[img.name] = img.path) +var populateImageLinks = async () => (await getJSON(`${root}api/getPictures`)).forEach(img => imagelinks[img.name] = img.path) populateImageLinks() diff --git a/views/head.ejs b/views/head.ejs index f2dec05e..dddb18dc 100644 --- a/views/head.ejs +++ b/views/head.ejs @@ -1,12 +1,13 @@ Clusterio - - - - - - - + + + + + + + + diff --git a/views/nav.ejs b/views/nav.ejs index a6b300a2..a6ca3760 100644 --- a/views/nav.ejs +++ b/views/nav.ejs @@ -1,12 +1,12 @@