Last active
August 26, 2024 23:35
-
-
Save stmcallister/3602522bcbe45596e4763c84034587a1 to your computer and use it in GitHub Desktop.
Example of using ngrok.forward method in the ngrok-python SDK
This file contains 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
from http.server import SimpleHTTPRequestHandler, HTTPServer | |
# install the ngrok page with `pip install ngrok` | |
import ngrok, logging | |
# RequestHandler -- A handler to create simple HTTP server that services specified HTML file | |
class RequestHandler(SimpleHTTPRequestHandler): | |
def do_GET(self): | |
# Set the request path to 'index.html' | |
self.path = 'index.html' | |
return SimpleHTTPRequestHandler.do_GET(self) | |
# Configure INFO logging for our app | |
logging.basicConfig(level=logging.INFO) | |
# Start HTTP server on port 8080 using the RequestHandler | |
server = HTTPServer(("localhost", 8080), RequestHandler) | |
# Establish connectivity to app with the `ngrok.forward` method | |
listener = ngrok.forward("localhost:8080", authtoken_from_env=True, domain="scott-python.ngrok.pizza") | |
server.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment