Skip to content

Commit a0f64b1

Browse files
hannojgV3RON
andauthored
feat: allow configuring Metro bind host (#70)
Co-authored-by: Szymon Chmal <szymon@chmal.it>
1 parent fc276be commit a0f64b1

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
__default__: patch
3+
---
4+
5+
Add a new host option to rn-harness.config for Metro bind host, replacing HARNESS_METRO_BIND_HOST.

packages/bundler-metro/src/factory.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,15 @@ export const getMetroInstance = async (
6666
.use('/status', getStatusMiddleware(projectRoot));
6767

6868
const ready = waitForBundler(reporter, abortSignal);
69+
const metroBindHost = harnessConfig.host?.trim();
70+
if (metroBindHost) {
71+
logger.debug(`Binding Metro server to host ${metroBindHost}`);
72+
}
73+
6974
const maybeServer = await Metro.runServer(config, {
7075
waitForBundler: true,
7176
unstable_extraMiddleware: [middleware],
77+
...(metroBindHost ? { host: metroBindHost } : {}),
7278
});
7379

7480
// Metro <0.83 returns the server directly, while 0.83+ returns an object with the server as a property.

packages/config/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const ConfigSchema = z
2121
.min(1, 'App registry component name is required'),
2222
runners: z.array(RunnerSchema).min(1, 'At least one runner is required'),
2323
defaultRunner: z.string().optional(),
24+
host: z.string().min(1, 'Host is required').optional(),
2425
webSocketPort: z.number().optional().default(3001),
2526
bridgeTimeout: z
2627
.number()

website/src/docs/getting-started/configuration.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ For Expo projects, the `entryPoint` should be set to the path specified in the `
8484
| `appRegistryComponentName` | **Required.** Name of the component registered with AppRegistry. |
8585
| `runners` | **Required.** Array of test runners (at least one required). |
8686
| `defaultRunner` | Default runner to use when none specified. |
87+
| `host` | Hostname or IP address to bind the Metro server to (default: Metro default). |
8788
| `bridgeTimeout` | Bridge timeout in milliseconds (default: `60000`). |
8889
| `bundleStartTimeout` | Bundle start timeout in milliseconds (default: `15000`). |
8990
| `maxAppRestarts` | Maximum number of app restarts when app fails to report ready (default: `2`). |

0 commit comments

Comments
 (0)