From c5494ee3c2e042ed6a80d2d49f2da32b7562cf7d Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Sun, 4 Jun 2023 23:20:15 +0200 Subject: [PATCH 1/2] fix undefined protocol and example page fixes #4478 --- packages/@uppy/companion/src/standalone/helper.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/@uppy/companion/src/standalone/helper.js b/packages/@uppy/companion/src/standalone/helper.js index 3e95b1fc8e..a5d0428819 100644 --- a/packages/@uppy/companion/src/standalone/helper.js +++ b/packages/@uppy/companion/src/standalone/helper.js @@ -41,11 +41,13 @@ const hasProtocol = (url) => { return url.startsWith('https://') || url.startsWith('http://') } +const companionProtocol = process.env.COMPANION_PROTOCOL || 'http' + function getCorsOrigins () { if (process.env.COMPANION_CLIENT_ORIGINS) { return process.env.COMPANION_CLIENT_ORIGINS .split(',') - .map((url) => (hasProtocol(url) ? url : `${process.env.COMPANION_PROTOCOL || 'http'}://${url}`)) + .map((url) => (hasProtocol(url) ? url : `${companionProtocol}://${url}`)) } if (process.env.COMPANION_CLIENT_ORIGINS_REGEX) { return new RegExp(process.env.COMPANION_CLIENT_ORIGINS_REGEX) @@ -128,7 +130,7 @@ const getConfigFromEnv = () => { }, server: { host: process.env.COMPANION_DOMAIN, - protocol: process.env.COMPANION_PROTOCOL, + protocol: companionProtocol, path: process.env.COMPANION_PATH, implicitPath: process.env.COMPANION_IMPLICIT_PATH, oauthDomain: process.env.COMPANION_OAUTH_DOMAIN, @@ -213,7 +215,7 @@ exports.buildHelpfulStartupMessage = (companionOptions) => { const buildURL = utils.getURLBuilder(companionOptions) const callbackURLs = [] Object.keys(companionOptions.providerOptions).forEach((providerName) => { - callbackURLs.push(buildURL(`/connect/${providerName}/redirect`, true)) + callbackURLs.push(buildURL(`/${providerName}/redirect`, true)) }) return stripIndent` @@ -227,7 +229,8 @@ exports.buildHelpfulStartupMessage = (companionOptions) => { While you did an awesome job on getting Companion running, this is just the welcome message, so let's talk about the places that really matter: - - Be sure to add ${callbackURLs.join(', ')} as your Oauth redirect uris on their corresponding developer interfaces. + - Be sure to add the following URLs as your Oauth redirect uris on their corresponding developer interfaces: + ${callbackURLs.join(', ')} - The URL ${buildURL('/metrics', true)} is available for statistics to keep Companion running smoothly - https://github.com/transloadit/uppy/issues - report your bugs here From 0e2618bc3e55565c57419eb988b27125d20a74fe Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Sun, 4 Jun 2023 23:40:42 +0200 Subject: [PATCH 2/2] fix companion implicitpath fixes #4468 --- .../companion/src/server/helpers/utils.js | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/@uppy/companion/src/server/helpers/utils.js b/packages/@uppy/companion/src/server/helpers/utils.js index 5cf4f6db42..d29d0a7496 100644 --- a/packages/@uppy/companion/src/server/helpers/utils.js +++ b/packages/@uppy/companion/src/server/helpers/utils.js @@ -41,24 +41,28 @@ module.exports.getURLBuilder = (options) => { /** * Builds companion targeted url * - * @param {string} path the tail path of the url + * @param {string} subPath the tail path of the url * @param {boolean} isExternal if the url is for the external world * @param {boolean} [excludeHost] if the server domain and protocol should be included */ - const buildURL = (path, isExternal, excludeHost) => { - let url = path - // supports for no path specified too - if (isExternal) { - url = `${options.server.implicitPath || ''}${url}` + const buildURL = (subPath, isExternal, excludeHost) => { + let path = '' + + if (isExternal && options.server.implicitPath) { + path += options.server.implicitPath + } + + if (options.server.path) { + path += options.server.path } - url = `${options.server.path || ''}${url}` + path += subPath - if (!excludeHost) { - url = `${options.server.protocol}://${options.server.host}${url}` + if (excludeHost) { + return path } - return url + return `${options.server.protocol}://${options.server.host}${path}` } return buildURL