diff --git a/packages/@uppy/companion-client/src/Provider.js b/packages/@uppy/companion-client/src/Provider.js index 5c120393bd..069406be60 100644 --- a/packages/@uppy/companion-client/src/Provider.js +++ b/packages/@uppy/companion-client/src/Provider.js @@ -83,8 +83,8 @@ module.exports = class Provider extends RequestClient { plugin.opts.serverPattern = pattern } else { // does not start with https:// - if (/^(?!https?:\/\/).*$/.test(opts.serverUrl)) { - plugin.opts.serverPattern = `${location.protocol}//${opts.serverUrl.replace(/^\/\//, '')}` + if (/^(?!https?:\/\/).*$/i.test(opts.serverUrl)) { + plugin.opts.serverPattern = `https://${opts.serverUrl.replace(/^\/\//, '')}` } else { plugin.opts.serverPattern = opts.serverUrl } diff --git a/packages/@uppy/utils/src/getSocketHost.js b/packages/@uppy/utils/src/getSocketHost.js index 52b01b6473..2ee8e9be09 100644 --- a/packages/@uppy/utils/src/getSocketHost.js +++ b/packages/@uppy/utils/src/getSocketHost.js @@ -1,8 +1,8 @@ module.exports = function getSocketHost (url) { // get the host domain - var regex = /^(?:https?:\/\/|\/\/)?(?:[^@\n]+@)?(?:www\.)?([^\n]+)/ + var regex = /^(?:https?:\/\/|\/\/)?(?:[^@\n]+@)?(?:www\.)?([^\n]+)/i var host = regex.exec(url)[1] - var socketProtocol = location.protocol === 'https:' ? 'wss' : 'ws' + var socketProtocol = /^http:\/\//i.test(url) ? 'ws' : 'wss' return `${socketProtocol}://${host}` } diff --git a/packages/@uppy/utils/src/getSocketHost.test.js b/packages/@uppy/utils/src/getSocketHost.test.js index 037f32b94b..a8254534ec 100644 --- a/packages/@uppy/utils/src/getSocketHost.test.js +++ b/packages/@uppy/utils/src/getSocketHost.test.js @@ -4,6 +4,18 @@ describe('getSocketHost', () => { it('should get the host from the specified url', () => { expect( getSocketHost('https://foo.bar/a/b/cd?e=fghi&l=k&m=n') - ).toEqual('ws://foo.bar/a/b/cd?e=fghi&l=k&m=n') + ).toEqual('wss://foo.bar/a/b/cd?e=fghi&l=k&m=n') + + expect( + getSocketHost('Https://foo.bar/a/b/cd?e=fghi&l=k&m=n') + ).toEqual('wss://foo.bar/a/b/cd?e=fghi&l=k&m=n') + + expect( + getSocketHost('foo.bar/a/b/cd?e=fghi&l=k&m=n') + ).toEqual('wss://foo.bar/a/b/cd?e=fghi&l=k&m=n') + + expect( + getSocketHost('http://foo.bar/a/b/cd?e=fghi&l=k&m=n') + ).toEqual('ws://foo.bar/a/b/cd?e=fghi&l=k&m=n') }) })