You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
01/software/source/server/tunnel.py

31 lines
1013 B

import ngrok
10 months ago
import pyqrcode
from ..utils.print_markdown import print_markdown
def create_tunnel(
server_host="localhost", server_port=10101, qr=False, domain=None
):
"""
To use most of ngroks features, youll need an authtoken. To obtain one, sign up for free at ngrok.com and
retrieve it from the authtoken page in your ngrok dashboard.
https://dashboard.ngrok.com/get-started/your-authtoken
You can set it as `NGROK_AUTHTOKEN` in your environment variables
"""
print_markdown("Exposing server to the internet...")
if domain:
listener = ngrok.forward(f"{server_host}:{server_port}", authtoken_from_env=True, domain=domain)
else:
listener = ngrok.forward(f"{server_host}:{server_port}", authtoken_from_env=True)
listener_url = listener.url()
10 months ago
print(f"Ingress established at: {listener_url}");
if listener_url and qr:
text = pyqrcode.create(listener_url)
10 months ago
print(text.terminal(quiet_zone=1))
return listener_url