mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-18 17:16:00 +00:00
Merge pull request #1393 from transloadit/remove-window-location
companion-client: remove the use of window.location
This commit is contained in:
commit
d3a6be786d
3 changed files with 17 additions and 5 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue