Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3244021
D6268.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D6268.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D6268: [native] Default to 'natDevHostname' from expo config
Attached
Detach File
Event Timeline
Log In to Comment