Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Host IP in metro.config.js #1087

Closed
aleksnied opened this issue Sep 22, 2023 · 1 comment
Closed

Host IP in metro.config.js #1087

aleksnied opened this issue Sep 22, 2023 · 1 comment

Comments

@aleksnied
Copy link

Do you want to request a feature or report a bug?

Request a feature

What is the current behavior?

metro.config.js server config allows for input of port only, it would be great if it could accept host as well, so we could dynamically overwrite this with an IP address:

defaultConfig.server = { port: 8081, host: 192.168.0.234 }

Use case:
When deploying to a physical device, the device connects to metro over WiFi. This means that offline app functionality cannot be tested without disconnecting from metro. With a host override in the config, we could dynamically populate this with the device USB interface IP, routing the connection through USB and allowing the device WiFi to be switched off without getting disconnected from our metro server.

The react native debug interface allows you to do this manually in the app through the Configure Bundler menu so it should be fairly simple?

@aleksnied
Copy link
Author

Actually, I've just noticed that

react-native-xcode.sh attempts to grab the USB IP Address so that physical device can connect to metro over USB. However your script only checks a few network interface numbers, up to en8, then falls back to computer LAN IP:

Enables iOS devices to get the IP address of the machine running Metro
if [[ ! "$SKIP_BUNDLING_METRO_IP" && "$CONFIGURATION" = *Debug* && ! "$PLATFORM_NAME" == *simulator ]]; then
  for num in 0 1 2 3 4 5 6 7 8; do
    IP=$(ipconfig getifaddr en${num})
    if [ ! -z "$IP" ]; then
      break
    fi
  done
  if [ -z "$IP" ]; then
    IP=$(ifconfig | grep 'inet ' | grep -v ' 127.' | grep -v ' 169.254.' |cut -d\   -f2  | awk 'NR==1{print $1}')
  fi

  echo "$IP" > "$DEST/ip.txt"

When I connect my iPhone via USB to my macbook, it's under en12, could you add more numbers to that for loop? :D

I will close this issue here and raise it against react-native itself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant