Files
react-native/packages/dev-middleware/src/utils/getDevServerUrl.js
T
Alex Hunt c82cf64a22 Move metro-inspector-proxy into dev-middleware (#39045)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39045

## Context

RFC: Decoupling Flipper from React Native core: https://github.com/react-native-community/discussions-and-proposals/pull/641

## Changes

- Relocates `metro-inspector-proxy` source from the Metro repo into the React Native repo as part of the `react-native/dev-middleware` package.
    - Drops the `runInspectorProxy` entry point.
- Attaches the Inspector Proxy to the `createDevMiddleware()` API as the new integration point for this functionality.
- Documents migrated endpoints + usage of `createDevMiddleware()` in README.

Changelog: [Internal]
Metro changelog: None (`metro-inspector-proxy` is now an internal component of `react-native`, covered in the [release notes for 0.78.1](https://github.com/facebook/metro/releases/tag/v0.78.1))

Reviewed By: motiz88, blakef

Differential Revision: D48066213

fbshipit-source-id: 3fbef5d881f6f451cb5955dcbbc362c53347437e
2023-08-18 01:38:10 -07:00

33 lines
818 B
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
* @oncall react_native
*/
import type {IncomingMessage} from 'http';
import net from 'net';
import {TLSSocket} from 'tls';
/**
* Get the base URL to address the current development server.
*/
export default function getDevServerUrl(req: IncomingMessage): string {
const scheme =
req.socket instanceof TLSSocket && req.socket.encrypted === true
? 'https'
: 'http';
const {localAddress, localPort} = req.socket;
const address =
localAddress && net.isIPv6(localAddress)
? `[${localAddress}]`
: localAddress;
return `${scheme}://${address}:${localPort}`;
}