Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix companion implicitpath #4484

Merged
merged 3 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions packages/@uppy/companion/src/server/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions packages/@uppy/companion/src/standalone/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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`
Expand All @@ -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

Expand Down