From a2f564b6e80253c96224350f0ecb266fb2e593bd Mon Sep 17 00:00:00 2001 From: GermanBluefox Date: Thu, 9 Jun 2022 14:50:35 +0200 Subject: [PATCH] * (bluefox) Allowed to work behind reverse proxy --- README.md | 275 +++++++++++++++++++++++----------------------- package.json | 34 +++--- src/Connection.js | 24 ++-- 3 files changed, 168 insertions(+), 165 deletions(-) diff --git a/README.md b/README.md index 4caee2a..f2282f7 100644 --- a/README.md +++ b/README.md @@ -616,218 +616,221 @@ The icons may not be reused in other projects without the proper flaticon licens ### **WORK IN PROGRESS** --> -## Changelog +## Changelog +### **WORK IN PROGRESS** +* (bluefox) Allowed to work behind reverse proxy + ### 2.1.0 (2022-05-09) -* (bluefox) Changes were synchronized with adapter-react-v5 - +* (bluefox) Changes were synchronized with adapter-react-v5 + ### 2.0.22 (2022-03-18) -* (AlCalzone) fix: include transform-runtime babel plugin #28 - +* (AlCalzone) fix: include transform-runtime babel plugin #28 + ### 2.0.21 (2022-02-16) -* (bluefox) Fixed the theme toggle - +* (bluefox) Fixed the theme toggle + ### 2.0.20 (2022-02-16) -* (bluefox) Added rename and delete functions for web applications - +* (bluefox) Added rename and delete functions for web applications + ### 2.0.19 (2022-02-14) -* (bluefox) Corrected function `getSvgFromData` in Image object - +* (bluefox) Corrected function `getSvgFromData` in Image object + ### 2.0.18 (2022-02-09) -* (bluefox) Removed deprecated option "disableBackdropClick" - +* (bluefox) Removed deprecated option "disableBackdropClick" + ### 2.0.17 (2022-01-29) -* (bluefox) Added logout command - +* (bluefox) Added logout command + ### 2.0.16 (2022-01-28) -* (bluefox) Allowed calling getGroups in web applications too - +* (bluefox) Allowed calling getGroups in web applications too + ### 2.0.15 (2022-01-18) -* (bluefox) Added the preparation for vis - +* (bluefox) Added the preparation for vis + ### 2.0.14 (2021-10-30) * (bluefox) Added the theme switch button -* (bluefox) Added new theme for vendor - +* (bluefox) Added new theme for vendor + ### 2.0.13 (2021-09-11) -* (bluefox) Small fix for the saving - +* (bluefox) Small fix for the saving + ### 2.0.12 (2021-09-03) -* (bluefox) Allowed to use the filter function for SelectID dialog. - +* (bluefox) Allowed to use the filter function for SelectID dialog. + ### 2.0.11 (2021-09-02) -* (bluefox) Added scrollbar in the CRON dialog - +* (bluefox) Added scrollbar in the CRON dialog + ### 2.0.10 (2021-08-31) -* (bluefox) Allowed the managing sentry settings - +* (bluefox) Allowed the managing sentry settings + ### 2.0.9 (2021-08-11) -* (bluefox) Updated the objects browser - +* (bluefox) Updated the objects browser + ### 2.0.8 (2021-07-31) -* (bluefox) Added list of themes - +* (bluefox) Added list of themes + ### 2.0.6 (2021-07-29) -* (bluefox) Added the vendor support - +* (bluefox) Added the vendor support + ### 2.0.4 (2021-07-26) -* (bluefox) Added the formula icon - +* (bluefox) Added the formula icon + ### 2.0.3 (2021-07-20) -* (bluefox) Fixed communication with admin4 - +* (bluefox) Fixed communication with admin4 + ### 2.0.1 (2021-07-13) * (bluefox) Breaking change: Update @material-ui/core to 4.12.x -* (bluefox) Fix getForeignObjects for web - +* (bluefox) Fix getForeignObjects for web + ### 1.6.31 (2021-07-12) -* (bluefox) Changed the filter of objects - +* (bluefox) Changed the filter of objects + ### 1.6.30 (2021-06-30) -* (bluefox) Corrected the export of objects in object list - +* (bluefox) Corrected the export of objects in object list + ### 1.6.29 (2021-06-27) -* (bluefox) Corrected translations - +* (bluefox) Corrected translations + ### 1.6.28 (2021-06-11) -* (bluefox) Corrected the "Select with icon" component - +* (bluefox) Corrected the "Select with icon" component + ### 1.6.27 (2021-06-10) -* (bluefox) Corrected some errors in connection - +* (bluefox) Corrected some errors in connection + ### 1.6.26 (2021-06-06) -* (bluefox) Fixed the icon selector component - +* (bluefox) Fixed the icon selector component + ### 1.6.25 (2021-06-05) * (bluefox) Fixed the icon selector component -* (UncleSamSwiss) Added @material-ui/icons dependency. - +* (UncleSamSwiss) Added @material-ui/icons dependency. + ### 1.6.24 (2021-06-04) -* (bluefox) Added the clear button to the CRON dialog - +* (bluefox) Added the clear button to the CRON dialog + ### 1.6.23 (2021-06-03) -* (bluefox) Added the icon selector component - +* (bluefox) Added the icon selector component + ### 1.6.22 (2021-05-24) * (bluefox) Fixed the object subscription -* (bluefox) Fixed the encryption and decryption of the native fields - +* (bluefox) Fixed the encryption and decryption of the native fields + ### 1.6.21 (2021-05-19) -* (bluefox) Fixed the layout for the "selectID" dialog - +* (bluefox) Fixed the layout for the "selectID" dialog + ### 1.6.20 (2021-05-16) -* (bluefox) Make it admin4 compatible - +* (bluefox) Make it admin4 compatible + ### 1.6.19 (2021-05-16) -* (bluefox) Fixed the load of system configuration - +* (bluefox) Fixed the load of system configuration + ### 1.6.18 (2021-05-16) -* (bluefox) Added the rendering of `
` too in texts - +* (bluefox) Added the rendering of `
` too in texts + ### 1.6.17 (2021-05-14) -* (bluefox) Updated save buttons on the bottom - +* (bluefox) Updated save buttons on the bottom + ### 1.6.16 (2021-05-12) -* (bluefox) Updated the CRON dialog - +* (bluefox) Updated the CRON dialog + ### 1.6.15 (2021-05-10) * (UncleSamSwiss) Fixed: Dependencies of produced npm package now contain all required packages -* (bluefox) Fixed translations - +* (bluefox) Fixed translations + ### 1.6.14 (2021-05-06) -* (bluefox) Fixed translations - +* (bluefox) Fixed translations + ### 1.6.13 (2021-05-05) * (bluefox) Fixed translations -* (bluefox) Added two new components: SelectWithIcon, TextWithIcon - +* (bluefox) Added two new components: SelectWithIcon, TextWithIcon + ### 1.6.12 (2021-05-02) -* (bluefox) Fixed translations - +* (bluefox) Fixed translations + ### 1.6.11 (2021-05-01) -* (bluefox) Allowed to change the color of object icons. - +* (bluefox) Allowed to change the color of object icons. + ### 1.6.10 (2021-04-22) -* (bluefox) Fixed some errors in the object browser - +* (bluefox) Fixed some errors in the object browser + ### 1.6.9 (2021-04-17) -* (bluefox) Updated the expert icon - +* (bluefox) Updated the expert icon + ### 1.6.8 (2021-03-31) -* (bluefox) The save buttons are moved into new component - +* (bluefox) The save buttons are moved into new component + ### 1.6.7 (2021-03-29) -* (bluefox) The object browser was updated - +* (bluefox) The object browser was updated + ### 1.6.6 (2021-03-22) -* (bluefox) Fix error with `getAdapterInstances` - +* (bluefox) Fix error with `getAdapterInstances` + ### 1.6.5 (2021-03-19) -* (bluefox) Fix error with `getAdapterInstances(true)` - +* (bluefox) Fix error with `getAdapterInstances(true)` + ### 1.6.4 (2021-03-18) -* (bluefox) Added CRON dialogs - +* (bluefox) Added CRON dialogs + ### 1.6.3 (2021-03-07) -* (bluefox) Added "restartController" function - +* (bluefox) Added "restartController" function + ### 1.6.2 (2021-03-01) -* (bluefox) Added Icon component. - +* (bluefox) Added Icon component. + ### 1.6.1 (2020-12-27) -* (bluefox) Allow checking the configuration before the saving. - +* (bluefox) Allow checking the configuration before the saving. + ### 1.6.0 (2020-12-27) * (bluefox) merged changes from admin -* (bluefox) all icons are outsourced - +* (bluefox) all icons are outsourced + ### 1.5.5 (2020-12-21) -* (bluefox) init sentry with the unique system ID. - +* (bluefox) init sentry with the unique system ID. + ### 1.5.4 (2020-12-19) -* (bluefox) Added table component - +* (bluefox) Added table component + ### 1.5.3 (2020-12-13) -* (bluefox) Corrected error in select ID dialog - +* (bluefox) Corrected error in select ID dialog + ### 1.5.1 (2020-12-12) -* (bluefox) The confirmation dialog could be suppressed - +* (bluefox) The confirmation dialog could be suppressed + ### 1.5.0 (2020-12-10) -* (bluefox) Added the editable table - +* (bluefox) Added the editable table + ### 1.4.11 (2020-12-05) -* (bluefox) Better multiple states selection - +* (bluefox) Better multiple states selection + ### 1.4.10 (2020-11-29) -* (bluefox) Added errors to the connection class - +* (bluefox) Added errors to the connection class + ### 1.4.9 (2020-11-23) -* (bluefox) Corrected the `removeSmartName` function - +* (bluefox) Corrected the `removeSmartName` function + ### 1.4.8 (2020-11-10) -* (bluefox) Allow calls like `Utils.getObjectNameFromObj(obj, I18n.getLanguage())` - +* (bluefox) Allow calls like `Utils.getObjectNameFromObj(obj, I18n.getLanguage())` + ### 1.4.6 (2020-11-07) * (bluefox) Better icon processing -* (bluefox) Added getParentId function - +* (bluefox) Added getParentId function + ### 1.4.4 (2020-11-02) -* (bluefox) Fixed the React warning - +* (bluefox) Fixed the React warning + ### 1.4.3 (2020-10-30) -* (bluefox) Optimize the loading - +* (bluefox) Optimize the loading + ### 1.4.2 (2020-10-29) -* (UncleSamSwiss) More JSDoc issues fixed - +* (UncleSamSwiss) More JSDoc issues fixed + ### 1.4.1 (2020-10-20) * (UncleSamSwiss) Made Router generic * (UncleSamSwiss) Fixed getThemeName(), it will always return a string (never null). -* (UncleSamSwiss) Fixed issue with Router DTS not properly extending React.Component<> - +* (UncleSamSwiss) Fixed issue with Router DTS not properly extending React.Component<> + ### 1.4.0 (2020-10-04) -* (UncleSamSwiss) added a lot of JSDoc comments and fixed some errors - +* (UncleSamSwiss) added a lot of JSDoc comments and fixed some errors + ## License The MIT License (MIT) @@ -849,4 +852,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SOFTWARE. diff --git a/package.json b/package.json index 5afb3a4..9f9fc7a 100644 --- a/package.json +++ b/package.json @@ -32,32 +32,32 @@ }, "homepage": "https://github.com/ioBroker/adapter-react#readme", "dependencies": { - "@sentry/browser": "^6.18.2", - "@sentry/integrations": "^6.18.2", - "@material-ui/core": "^4.12.3", - "@material-ui/icons": "^4.11.2", + "@sentry/browser": "^7.1.1", + "@sentry/integrations": "^7.1.1", + "@material-ui/core": "^4.12.4", + "@material-ui/icons": "^4.11.3", "react-color": "^2.19.3", "react-colorful": "^5.5.1", - "react-dropzone": "^12.0.4", + "react-dropzone": "^14.2.1", "react-inlinesvg": "^2.3.0", - "@types/iobroker": "^4.0.1" + "@types/iobroker": "^4.0.4" }, "devDependencies": { - "@alcalzone/release-script": "^3.5.6", - "@alcalzone/release-script-plugin-license": "^3.5.3", - "@babel/core": "^7.17.7", - "@babel/plugin-proposal-class-properties": "^7.16.7", - "@babel/plugin-transform-runtime": "^7.17.0", - "@babel/preset-env": "^7.16.11", - "@babel/preset-flow": "^7.16.7", - "@babel/preset-react": "^7.16.7", - "@types/react": "^17.0.40", + "@alcalzone/release-script": "^3.5.9", + "@alcalzone/release-script-plugin-license": "^3.5.9", + "@babel/core": "^7.18.2", + "@babel/plugin-proposal-class-properties": "^7.17.12", + "@babel/plugin-transform-runtime": "^7.18.2", + "@babel/preset-env": "^7.18.2", + "@babel/preset-flow": "^7.17.12", + "@babel/preset-react": "^7.17.12", + "@types/react": "^18.0.12", "babel": "^6.23.0", - "del": "^6.0.0", + "del": "^6.1.1", "gulp": "^4.0.2", "gulp-babel": "^8.0.0", "gulp-sourcemaps": "^3.0.0", "gulp-typescript": "^6.0.0-alpha.1", - "typescript": "^4.6.2" + "typescript": "^4.7.3" } } diff --git a/src/Connection.js b/src/Connection.js index e003cc2..4320a00 100644 --- a/src/Connection.js +++ b/src/Connection.js @@ -180,8 +180,13 @@ class Connection { host = parts[1]; } } - - const url = port ? `${protocol}://${host}:${port}` : `${protocol}://${host}`; + // get current path + let path = window.location.pathname; + const pos = path.lastIndexOf('/'); + if (pos !== -1) { + path = path.substring(0, pos + 1); + } + const url = port ? `${protocol}://${host}:${port}${path}` : `${protocol}://${host}${path}`; this._socket = window.io.connect( url, @@ -863,10 +868,6 @@ class Connection { * @returns {Promise} */ getAdapterInstances(adapter, update) { - if (Connection.isWeb()) { - return Promise.reject('Allowed only in admin'); - } - if (typeof adapter === 'boolean') { update = adapter; adapter = ''; @@ -885,8 +886,8 @@ class Connection { let timeout = setTimeout(() => { timeout = null; this.getObjectView( - `system.adapter.${adapter}.`, - `system.adapter.${adapter}.\u9999`, + `system.adapter.${adapter ? adapter + '.' : ''}`, + `system.adapter.${adapter ? adapter + '.' : ''}\u9999`, 'instance' ) .then(items => resolve(Object.keys(items).map(id => fixAdminUI(items[id])))) @@ -2116,7 +2117,7 @@ class Connection { this._socket.emit('getHostByIp', ipOrHostName, (ip, host) => { const IPs4 = [{name: '[IPv4] 0.0.0.0 - Listen on all IPs', address: '0.0.0.0', family: 'ipv4'}]; const IPs6 = [{name: '[IPv6] :: - Listen on all IPs', address: '::', family: 'ipv6'}]; - if (host.native?.hardware?.networkInterfaces) { + if (host?.native?.hardware?.networkInterfaces) { for (const eth in host.native.hardware.networkInterfaces) { if (!host.native.hardware.networkInterfaces.hasOwnProperty(eth)) { continue; @@ -2376,9 +2377,8 @@ class Connection { resolve(json); } }) - .catch(e => { - reject('getCurrentSession: ' + e); - }); + .catch(e => + reject('getCurrentSession: ' + e)); }); }