Page MenuHomePhabricator

D6268.diff
No OneTemporary

D6268.diff

diff --git a/native/utils/dev-hostname.js b/native/utils/dev-hostname.js
--- a/native/utils/dev-hostname.js
+++ b/native/utils/dev-hostname.js
@@ -1,31 +1,45 @@
// @flow
+import Constants from 'expo-constants';
-let natDevHostname: string;
let warnNatDevHostnameUndefined = true;
const defaultNatDevHostname = '192.168.1.1';
-try {
- // this is your machine's hostname in the local network
- // usually it looks like this: 192.168.1.x
- // to find it you may want to use `ifconfig | grep '192.168'`
- // command in the terminal
- // example of native/facts/network.json:
- // { "natDevHostname": "192.168.1.x" }
- // $FlowExpectedError: That's a conditional require so the file may not exist
- const hostname: string = require('../facts/network').natDevHostname;
- natDevHostname = hostname;
+function readHostnameFromExpoConfig(): ?string {
+ const { natDevHostname: detectedHostname } = Constants.expoConfig.extra || {};
+ if (!detectedHostname || typeof detectedHostname !== 'string') {
+ return null;
+ }
warnNatDevHostnameUndefined = false;
-} catch (e) {
- natDevHostname = defaultNatDevHostname;
+ return detectedHostname;
}
+function readHostnameFromNetworkJson(): string {
+ try {
+ // this is your machine's hostname in the local network
+ // usually it looks like this: 192.168.1.x
+ // to find it you may want to use `ifconfig | grep '192.168'`
+ // command in the terminal
+ // example of native/facts/network.json:
+ // { "natDevHostname": "192.168.1.x" }
+ // $FlowExpectedError: It's a conditional require so the file may not exist
+ const hostname: string = require('../facts/network').natDevHostname;
+ warnNatDevHostnameUndefined = false;
+ return hostname;
+ } catch (e) {
+ return defaultNatDevHostname;
+ }
+}
+
+const natDevHostname: string =
+ readHostnameFromExpoConfig() ?? readHostnameFromNetworkJson();
+
function checkForMissingNatDevHostname() {
if (!warnNatDevHostnameUndefined) {
return;
}
console.warn(
- 'Failed to read natDevHostname. ' +
- 'Please specify it in native/facts/network.json',
+ 'Failed to autodetect natDevHostname. ' +
+ 'Please specify it manually in native/facts/network.json',
);
warnNatDevHostnameUndefined = false;
}

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 15, 10:28 AM (13 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2494093
Default Alt Text
D6268.diff (2 KB)

Event Timeline