01/software/source/server/tunnel.py

31 lines
1013 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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