MCPcopy
hub / github.com/react/create-react-app / resolveLoopback

Function resolveLoopback

packages/react-dev-utils/WebpackDevServerUtils.js:232–259  ·  view source on GitHub ↗
(proxy)

Source from the content-addressed store, hash-verified

230}
231
232function resolveLoopback(proxy) {
233 const o = url.parse(proxy);
234 o.host = undefined;
235 if (o.hostname !== 'localhost') {
236 return proxy;
237 }
238 // Unfortunately, many languages (unlike node) do not yet support IPv6.
239 // This means even though localhost resolves to ::1, the application
240 // must fall back to IPv4 (on 127.0.0.1).
241 // We can re-enable this in a few years.
242 /*try {
243 o.hostname = address.ipv6() ? '::1' : '127.0.0.1';
244 } catch (_ignored) {
245 o.hostname = '127.0.0.1';
246 }*/
247
248 try {
249 // Check if we're on a network; if we are, chances are we can resolve
250 // localhost. Otherwise, we can just be safe and assume localhost is
251 // IPv4 for maximum compatibility.
252 if (!address.ip()) {
253 o.hostname = '127.0.0.1';
254 }
255 } catch (_ignored) {
256 o.hostname = '127.0.0.1';
257 }
258 return url.format(o);
259}
260
261// We need to provide a custom onError function for httpProxyMiddleware.
262// It allows us to log custom error messages on the console.

Callers 1

prepareProxyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected