Skip to content

Instantly share code, notes, and snippets.

@gpichot
Created September 12, 2018 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gpichot/a9a7ef4f3ea71fe7e0f9e1694bc08a89 to your computer and use it in GitHub Desktop.
Save gpichot/a9a7ef4f3ea71fe7e0f9e1694bc08a89 to your computer and use it in GitHub Desktop.
Find a ngrok tunnel running locally and add it to the the django conf (iOS/Android development)
import requests
import urllib
ALLOWED_HOSTS = ["localhost", "127.0.0.1"]
# Try to find a runnning ngrok instance
try:
tunnels = requests.get('http://127.0.0.1:4040/api/tunnels')
url = tunnels.json()['tunnels'][0]['public_url']
ngrok_domain = urllib.parse.urlparse(url).netloc
print('\033[92mFound running ngrok tunnel: \033[1m{}\033[0m'.format(
ngrok_domain))
ALLOWED_HOSTS += [ngrok_domain]
MEDIA_URL = 'https://{}/media/'.format(ngrok_domain)
except:
print('\033[93mNo running ngrok instances found\033[0m')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment