Files
xen-orchestra/packages/xo-lib/fix-url.js
2015-03-04 17:31:14 +01:00

22 lines
474 B
JavaScript

'use strict';
//====================================================================
// Fix URL if necessary.
var URL_RE = /^(?:(?:http|ws)(s)?:\/\/)?(.*?)\/*(?:\/api\/)?(\?.*?)?(?:#.*)?$/;
function fixUrl(url) {
var matches = URL_RE.exec(url);
var isSecure = !!matches[1];
var hostAndPath = matches[2];
var search = matches[3];
return [
isSecure ? 'wss' : 'ws',
'://',
hostAndPath,
'/api/',
search,
].join('');
}
module.exports = fixUrl;