chore(dev-middleware): add localhost as default host in start command config (#44244)

Summary:
Inside [Re.Pack](https://github.com/callstack/repack) we consume command's options, to reduce the amount of assumptions that 3rd party tools need to make - we can move assigning default value to config command level, so default values will be aligned across tools.

For default `start` command this change doesn't change any behaviour.

## Changelog:

[INTERNAL] [CHANGED] - Add `localhost` as default host in `start` command config

Pull Request resolved: https://github.com/facebook/react-native/pull/44244

Test Plan: `start` command should work the same way as before.

Reviewed By: huntie

Differential Revision: D56567793

Pulled By: blakef

fbshipit-source-id: fe8f3686ae39a3d2996de11930a0d03364692adc
This commit is contained in:
szymonrybczak
2024-04-25 03:01:51 -07:00
committed by Facebook GitHub Bot
parent 78ab5f4b83
commit c402dcfe57
2 changed files with 4 additions and 5 deletions
@@ -27,7 +27,7 @@ const startCommand: Command = {
},
{
name: '--host <string>',
default: '',
default: 'localhost',
},
{
name: '--projectRoot <path>',
@@ -34,7 +34,7 @@ export type StartCommandArgs = {
cert?: string,
customLogReporterPath?: string,
experimentalDebugger: boolean,
host?: string,
host: string,
https?: boolean,
maxWorkers?: number,
key?: string,
@@ -63,14 +63,13 @@ async function runServer(
projectRoot: args.projectRoot,
sourceExts: args.sourceExts,
});
const hostname = args.host?.length ? args.host : 'localhost';
const {
projectRoot,
server: {port},
watchFolders,
} = metroConfig;
const protocol = args.https === true ? 'https' : 'http';
const devServerUrl = url.format({protocol, hostname, port});
const devServerUrl = url.format({protocol, hostname: args.host, port});
logger.info(`Welcome to React Native v${ctx.reactNativeVersion}`);
@@ -104,7 +103,7 @@ async function runServer(
messageSocketEndpoint,
eventsSocketEndpoint,
} = createDevServerMiddleware({
host: hostname,
host: args.host,
port,
watchFolders,
});