From 360454578791ec231bd04f41c2dfe50f68151a68 Mon Sep 17 00:00:00 2001 From: ryo Date: Tue, 4 Jul 2017 15:11:26 +0900 Subject: [PATCH 1/3] fix file upload issue when running in subdirectory https://github.com/RocketChat/Rocket.Chat/issues/6679 --- packages/rocketchat-cors/cors.js | 2 +- packages/rocketchat-file-upload/server/lib/requests.js | 3 ++- packages/rocketchat-lib/client/lib/settings.js | 4 ++-- .../rocketchat-lib/lib/startup/settingsOnLoadSiteUrl.js | 7 +++++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/rocketchat-cors/cors.js b/packages/rocketchat-cors/cors.js index 9b07501d8d3e..62d7e4b7e328 100644 --- a/packages/rocketchat-cors/cors.js +++ b/packages/rocketchat-cors/cors.js @@ -12,7 +12,7 @@ WebApp.rawConnectHandlers.use(function(req, res, next) { if (req.headers['content-type'] !== '' && req.headers['content-type'] !== undefined) { return next(); } - if (req.url.indexOf('/ufs/') === 0) { + if (req.url.indexOf(`${ __meteor_runtime_config__.ROOT_URL_PATH_PREFIX }/${UploadFS.config.storesPath}/`) === 0) { return next(); } diff --git a/packages/rocketchat-file-upload/server/lib/requests.js b/packages/rocketchat-file-upload/server/lib/requests.js index 1f759a2defef..175397de6fdb 100644 --- a/packages/rocketchat-file-upload/server/lib/requests.js +++ b/packages/rocketchat-file-upload/server/lib/requests.js @@ -7,7 +7,8 @@ RocketChat.settings.get('FileUpload_ProtectFiles', function(key, value) { protectedFiles = value; }); -WebApp.connectHandlers.use('/file-upload/', function(req, res, next) { +WebApp.connectHandlers.use(`${ __meteor_runtime_config__.ROOT_URL_PATH_PREFIX }/file-upload/`, function(req, res, next) { + const match = /^\/([^\/]+)\/(.*)/.exec(req.url); if (match[1]) { diff --git a/packages/rocketchat-lib/client/lib/settings.js b/packages/rocketchat-lib/client/lib/settings.js index 0f0c946ecd81..e2a769a7608d 100644 --- a/packages/rocketchat-lib/client/lib/settings.js +++ b/packages/rocketchat-lib/client/lib/settings.js @@ -59,8 +59,8 @@ Meteor.startup(function() { return c.stop(); } Meteor.setTimeout(function() { - if (__meteor_runtime_config__.ROOT_URL !== location.origin) { - const currentUrl = location.origin + __meteor_runtime_config__.ROOT_URL_PATH_PREFIX; + const currentUrl = location.origin + __meteor_runtime_config__.ROOT_URL_PATH_PREFIX; + if (__meteor_runtime_config__.ROOT_URL !== currentUrl) { swal({ type: 'warning', title: t('Warning'), diff --git a/packages/rocketchat-lib/lib/startup/settingsOnLoadSiteUrl.js b/packages/rocketchat-lib/lib/startup/settingsOnLoadSiteUrl.js index 17014a7dbe9b..6f9f9c79d052 100644 --- a/packages/rocketchat-lib/lib/startup/settingsOnLoadSiteUrl.js +++ b/packages/rocketchat-lib/lib/startup/settingsOnLoadSiteUrl.js @@ -10,10 +10,13 @@ RocketChat.settings.get('Site_Url', function(key, value) { host = match[1]; // prefix = match[2].replace(/\/$/, ''); } - __meteor_runtime_config__.ROOT_URL = host; + __meteor_runtime_config__.ROOT_URL = value; + + console.log('__meteor_runtime_config__.ROOT_URL_PATH_PREFIX =' + __meteor_runtime_config__.ROOT_URL_PATH_PREFIX) + console.log('__meteor_runtime_config__.ROOT_URL=' + __meteor_runtime_config__.ROOT_URL) if (Meteor.absoluteUrl.defaultOptions && Meteor.absoluteUrl.defaultOptions.rootUrl) { - Meteor.absoluteUrl.defaultOptions.rootUrl = host; + Meteor.absoluteUrl.defaultOptions.rootUrl = value; } if (Meteor.isServer) { RocketChat.hostname = host.replace(/^https?:\/\//, ''); From e0e60f8d58f89fcfd92a4709e1f34137b5625324 Mon Sep 17 00:00:00 2001 From: ryo Date: Tue, 4 Jul 2017 16:21:38 +0900 Subject: [PATCH 2/3] fix lint --- packages/rocketchat-lib/lib/startup/settingsOnLoadSiteUrl.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/rocketchat-lib/lib/startup/settingsOnLoadSiteUrl.js b/packages/rocketchat-lib/lib/startup/settingsOnLoadSiteUrl.js index 6f9f9c79d052..8e4c7d987e6f 100644 --- a/packages/rocketchat-lib/lib/startup/settingsOnLoadSiteUrl.js +++ b/packages/rocketchat-lib/lib/startup/settingsOnLoadSiteUrl.js @@ -12,9 +12,6 @@ RocketChat.settings.get('Site_Url', function(key, value) { } __meteor_runtime_config__.ROOT_URL = value; - console.log('__meteor_runtime_config__.ROOT_URL_PATH_PREFIX =' + __meteor_runtime_config__.ROOT_URL_PATH_PREFIX) - console.log('__meteor_runtime_config__.ROOT_URL=' + __meteor_runtime_config__.ROOT_URL) - if (Meteor.absoluteUrl.defaultOptions && Meteor.absoluteUrl.defaultOptions.rootUrl) { Meteor.absoluteUrl.defaultOptions.rootUrl = value; } From 6de7e464028bfdf5b261b0e23960249afcd298d2 Mon Sep 17 00:00:00 2001 From: ryo Date: Tue, 4 Jul 2017 16:41:04 +0900 Subject: [PATCH 3/3] fix lint --- packages/rocketchat-cors/cors.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/rocketchat-cors/cors.js b/packages/rocketchat-cors/cors.js index 62d7e4b7e328..6af8bc100344 100644 --- a/packages/rocketchat-cors/cors.js +++ b/packages/rocketchat-cors/cors.js @@ -2,7 +2,7 @@ import url from 'url'; -WebApp.rawConnectHandlers.use(function(req, res, next) { +WebApp.rawConnectHandlers.use(Meteor.bindEnvironment(function(req, res, next) { if (req._body) { return next(); } @@ -12,7 +12,7 @@ WebApp.rawConnectHandlers.use(function(req, res, next) { if (req.headers['content-type'] !== '' && req.headers['content-type'] !== undefined) { return next(); } - if (req.url.indexOf(`${ __meteor_runtime_config__.ROOT_URL_PATH_PREFIX }/${UploadFS.config.storesPath}/`) === 0) { + if (req.url.indexOf(`${ __meteor_runtime_config__.ROOT_URL_PATH_PREFIX }/ufs/`) === 0) { return next(); } @@ -36,7 +36,7 @@ WebApp.rawConnectHandlers.use(function(req, res, next) { return next(); }); -}); +})); WebApp.rawConnectHandlers.use(function(req, res, next) { if (/^\/(api|_timesync|sockjs|tap-i18n|__cordova)(\/|$)/.test(req.url)) {