uppy/packages/@uppy/utils/src/getSocketHost.js
2021-07-20 14:40:31 +02:00

8 lines
286 B
JavaScript

module.exports = 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}`
}