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

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import ngrok
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()
print(f"Ingress established at: {listener_url}");
if listener_url and qr:
text = pyqrcode.create(listener_url)
print(text.terminal(quiet_zone=1))
return listener_url