Skip to content

Commit 1444488

Browse files
refactor: code
1 parent 618ad78 commit 1444488

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

lib/options.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@
154154
"description": "Tells clients connected to devServer to use the provided path to connect.",
155155
"type": "string"
156156
},
157-
"username": {
158-
"description": "Tells clients connected to devServer to use the provided username to authenticate.",
159-
"type": "string"
160-
},
161157
"password": {
162158
"description": "Tells clients connected to devServer to use the provided password to authenticate.",
163159
"type": "string"
@@ -185,6 +181,10 @@
185181
"minLength": 1
186182
}
187183
]
184+
},
185+
"username": {
186+
"description": "Tells clients connected to devServer to use the provided username to authenticate.",
187+
"type": "string"
188188
}
189189
}
190190
}

lib/utils/DevServerPlugin.js

+5-12
Original file line numberDiff line numberDiff line change
@@ -107,39 +107,32 @@ class DevServerPlugin {
107107
/** @type {string} */
108108
let username = '';
109109

110-
// We are proxying dev server and need to specify custom `path`
111110
if (typeof options.client.webSocketURL.username !== 'undefined') {
112111
username = options.client.webSocketURL.username;
113112
}
114113

115114
/** @type {string} */
116115
let password = '';
117116

118-
// We are proxying dev server and need to specify custom `path`
119117
if (typeof options.client.webSocketURL.password !== 'undefined') {
120118
password = options.client.webSocketURL.password;
121119
}
122120

123-
/** @type {Record<string, any>} */
124-
const searchParams = {};
121+
const searchParams = new URLSearchParams();
125122

126123
if (typeof options.client.logging !== 'undefined') {
127-
searchParams.logging = options.client.logging;
124+
searchParams.set('logging', options.client.logging);
128125
}
129126

127+
const searchParamsString = searchParams.toString();
128+
130129
return encodeURIComponent(
131130
new URL(
132131
`${protocol}//${username}${password ? `:${password}` : ''}${
133132
username || password ? `@` : ''
134133
}${ipaddr.IPv6.isIPv6(host) ? `[${host}]` : host}${
135134
port ? `:${port}` : ''
136-
}${path || '/'}${
137-
Object.keys(searchParams).length > 0
138-
? `?${Object.entries(searchParams)
139-
.map(([key, value]) => `${key}=${value}`)
140-
.join('&')}`
141-
: ''
142-
}`
135+
}${path || '/'}${searchParamsString ? `?${searchParamsString}` : ''}`
143136
).toString()
144137
).replace(
145138
/[!'()*]/g,

0 commit comments

Comments
 (0)