Skip to content

Instantly share code, notes, and snippets.

@stmcallister
Last active August 26, 2024 23:35
Show Gist options
  • Save stmcallister/3602522bcbe45596e4763c84034587a1 to your computer and use it in GitHub Desktop.
Save stmcallister/3602522bcbe45596e4763c84034587a1 to your computer and use it in GitHub Desktop.
Example of using ngrok.forward method in the ngrok-python SDK
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