expo / expo-cli

Tools for creating, running, and deploying universal Expo and React Native apps
https://docs.expo.io/workflow/expo-cli/
2.6k stars 477 forks source link

[xdl] Enhance `expo start --tunnel` with Ngrok tunnel customization options via env. #4775

Closed lightSoulDev closed 6 months ago

lightSoulDev commented 8 months ago

Why

This pull request enhances the expo start --tunnel experience by introducing new environment variables and conditional logic for more control over the Ngrok tunnel setup. Specifically, it allows skipping the creation of a tunnel if the EXPO_TUNNEL_SKIP_CONNECT environment variable is set (EXPO_TUNNEL_USE_HTTPS must be set if that tunnel uses https protocol). Additionally, it provides the flexibility to use a custom Ngrok domain via the NGROK_HOSTNAME, NGROK_AUTHTOKEN, and NGROK_PORT environment variables.

Changes Made

  1. Added conditionals to check for the EXPO_TUNNEL_SKIP_CONNECT and NGROK_HOSTNAME environment variables.
  2. Introduced the EXPO_TUNNEL_USE_HTTPS environment variable for specifying HTTPS protocol usage.
  3. Modified the connectToNgrokInternalAsync method to incorporate these changes.

New Environment Variables

Usage Examples

  1. To skip tunnel creation and use an existing tunnel (e.g., when using cloudflared):
    
    EXPO_TUNNEL_SKIP_CONNECT=true expo start --tunnel

If existing tunnel is using https

EXPO_TUNNEL_SKIP_CONNECT=1 EXPO_TUNNEL_USE_HTTPS=1 expo start --tunnel


2. To create a tunnel on a custom ngrok domain
```bash
NGROK_HOSTNAME=my-custom-domain.com NGROK_AUTHTOKEN=xxxxxxx NGROK_PORT=8181 expo start --tunnel

Test Plan

I have been using these changes as patches for some time. I had to ensure that my app works as expected outside of my homelab. I set up a test HTTPS tunnel and needed this changes for Expo Go to work properly.

P.S. Simply running npx expo start with a specified port (e.g., 8181) did not yield the desired results. This issue arose when attempting to scan a QR code, as Expo Go was attempting to download an update from a URL structured as http://example.com:8181/...

Examples for testing are listed above. Sorry if I did sth wrong. Example output

NGROK_HOSTNAME=expo.example.dev EXPO_TUNNEL_SKIP_CONNECT=1 EXPO_TUNNEL_USE_HTTPS=1 npx expo start --tunnel
Starting project at /home/lightsoul/github/Lightsoul-Development/BB-native
Starting Metro Bundler
Tunnel ready
› Metro waiting on exp://expo.example.dev
Logs for your project will appear below. Press Ctrl+C to exit.
...
byCedric commented 6 months ago

Hi @lightSoulDev! Thanks for the PR, unfortunately this change was made on already deprecated parts of the global Expo CLI. This has been replaced by the versioned CLI.

If you think we should still move forward with this PR, please reopen the PR on github.com/expo/expo.

Hope this helps!