From ef772b725b605422716a13d214e85ea1167aa34d Mon Sep 17 00:00:00 2001 From: Felix Lo Date: Mon, 11 Sep 2023 01:26:18 +0800 Subject: [PATCH] Allow for mobile app or web services to retrieve proxy URL to access MainUI Signed-off-by: lsafelix75 --- app.js | 4 ++-- routes/api.js | 10 ++++++++++ routes/index.js | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index d0bf2b56..d12ca04d 100644 --- a/app.js +++ b/app.js @@ -110,7 +110,7 @@ if (config.system.subDomainCookies) { if (app.get('env') === 'development') { app.use(errorHandler()); } -if (system.getLoggerMorganOption()){ +if (system.getLoggerMorganOption()) { app.use(system.getLoggerMorganOption()); } // App configuration for all environments @@ -148,7 +148,7 @@ app.use(function (req, res, next) { next(); // No host in header, just go ahead } // If host matches names for full /* proxying, go ahead and just proxy it. - if (host.indexOf('remote.') === 0 || host.indexOf('home.') === 0) { + if (host.indexOf('remote.') === 0 || host === system.getProxyHost()) { //make sure this was not set by another server if (req.url.indexOf('/remote') != 0) { req.url = '/remote' + req.url; diff --git a/routes/api.js b/routes/api.js index 949c3037..4aa74299 100644 --- a/routes/api.js +++ b/routes/api.js @@ -34,3 +34,13 @@ exports.notificationssettingsget = function(req, res) { } res.send(config); }; + +exports.proxyurlget = function(req, res) { + var config = {}; + + + config.proxyurl = { + "url": system.getProxyURL() + }; + res.send(config); +}; diff --git a/routes/index.js b/routes/index.js index 5dd5dcbb..6a3526e9 100644 --- a/routes/index.js +++ b/routes/index.js @@ -228,6 +228,7 @@ Routes.prototype.setupAppRoutes = function (app) { // myOH API for mobile apps app.all('/api/v1/notifications*', this.ensureRestAuthenticated, this.setOpenhab, this.preassembleBody, api_routes.notificationsget); app.all('/api/v1/settings/notifications', this.ensureRestAuthenticated, this.setOpenhab, this.preassembleBody, api_routes.notificationssettingsget); + app.all('/api/v1/proxyurl', this.ensureRestAuthenticated, this.preassembleBody, this.setOpenhab, api_routes.proxyurlget); // Android app registration app.all('/addAndroidRegistration*', this.ensureRestAuthenticated, this.setOpenhab, this.preassembleBody, androidRegistrationService);