Skip to content

🎥 Make videos programmatically with React

Display network address

Jonny Burger824dc4bb8c45
diff --git a/packages/cli/src/get-network-address.ts b/packages/cli/src/get-network-address.ts
new file mode 100644
index 0000000000..92d55685ac
--- /dev/null
+++ b/packages/cli/src/get-network-address.ts
@@ -0,0 +1,13 @@
+import {networkInterfaces} from 'os';
+
+export const getNetworkAddress = (): string | undefined => {
+ for (const interfaceDetails of Object.values(networkInterfaces())) {
+ if (!interfaceDetails) continue;
+
+ for (const details of interfaceDetails) {
+ const {address, family, internal} = details;
+
+ if (family === 'IPv4' && !internal) return address;
+ }
+ }
+};
diff --git a/packages/cli/src/preview.ts b/packages/cli/src/preview.ts
index f4bbf6e61c..cf22f59432 100644
--- a/packages/cli/src/preview.ts
+++ b/packages/cli/src/preview.ts
@@ -1,8 +1,10 @@
import betterOpn from 'better-opn';
import path from 'path';
+import {chalk} from './chalk';
import {ConfigInternals} from './config';
import {getEnvironmentVariables} from './get-env';
import {getInputProps} from './get-input-props';
+import {getNetworkAddress} from './get-network-address';
import {Log} from './log';
import {parsedCli} from './parse-command-line';
import type {LiveEventsServer} from './preview-server/live-events';
@@ -83,7 +85,17 @@ export const previewCommand = async (remotionRoot: string) => {
);
setLiveEventsListener(liveEventsServer);
- Log.info(`Server running on http://localhost:${port}`);
+ const networkAddress = getNetworkAddress();
+ if (networkAddress) {
+ Log.info(
+ `Server ready - Local: ${chalk.underline(
+ `http://localhost:${port}`
+ )}, Network: ${chalk.underline(`http://${networkAddress}:${port}`)}`
+ );
+ } else {
+ Log.info(`Running on http://localhost:${port}`);
+ }
+
betterOpn(`http://localhost:${port}`);
await new Promise(noop);
};