Path: blob/master/modules/ngrok.py
3055 views
import ngrok12# Connect to ngrok for ingress3def connect(token, port, options):4account = None5if token is None:6token = 'None'7else:8if ':' in token:9# token = authtoken:username:password10token, username, password = token.split(':', 2)11account = f"{username}:{password}"1213# For all options see: https://github.com/ngrok/ngrok-py/blob/main/examples/ngrok-connect-full.py14if not options.get('authtoken_from_env'):15options['authtoken'] = token16if account:17options['basic_auth'] = account18if not options.get('session_metadata'):19options['session_metadata'] = 'stable-diffusion-webui'202122try:23public_url = ngrok.connect(f"127.0.0.1:{port}", **options).url()24except Exception as e:25print(f'Invalid ngrok authtoken? ngrok connection aborted due to: {e}\n'26f'Your token: {token}, get the right one on https://dashboard.ngrok.com/get-started/your-authtoken')27else:28print(f'ngrok connected to localhost:{port}! URL: {public_url}\n'29'You can use this link after the launch is complete.')303132