Created
September 12, 2018 08:24
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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