uppy/packages/@uppy/utils/src/getSocketHost.js
2022-05-23 09:40:50 +02:00

8 lines
284 B
JavaScript

export default function getSocketHost (url) {
// get the host domain
const regex = /^(?:https?:\/\/|\/\/)?(?:[^@\n]+@)?(?:www\.)?([^\n]+)/i
const host = regex.exec(url)[1]
const socketProtocol = /^http:\/\//i.test(url) ? 'ws' : 'wss'
return `${socketProtocol}://${host}`
}