source: frontend/node_modules/@pmmmwh/react-refresh-webpack-plugin/sockets/utils/getUrlFromParts.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1014 bytes
Line 
1/**
2 * Create a valid URL from parsed URL parts.
3 * @param {import('./getSocketUrlParts').SocketUrlParts} urlParts The parsed URL parts.
4 * @param {import('./getWDSMetadata').WDSMetaObj} [metadata] The parsed WDS metadata object.
5 * @returns {string} The generated URL.
6 */
7function urlFromParts(urlParts, metadata) {
8 if (typeof metadata === 'undefined') {
9 metadata = {};
10 }
11
12 let fullProtocol = 'http:';
13 if (urlParts.protocol) {
14 fullProtocol = urlParts.protocol;
15 }
16 if (metadata.enforceWs) {
17 fullProtocol = fullProtocol.replace(/^(?:http|.+-extension|file)/i, 'ws');
18 }
19
20 fullProtocol = fullProtocol + '//';
21
22 let fullHost = urlParts.hostname;
23 if (urlParts.auth) {
24 const fullAuth = urlParts.auth.split(':').map(encodeURIComponent).join(':') + '@';
25 fullHost = fullAuth + fullHost;
26 }
27 if (urlParts.port) {
28 fullHost = fullHost + ':' + urlParts.port;
29 }
30
31 const url = new URL(urlParts.pathname, fullProtocol + fullHost);
32 return url.href;
33}
34
35module.exports = urlFromParts;
Note: See TracBrowser for help on using the repository browser.