Skip to content

Instantly share code, notes, and snippets.

@alexdlaird
Last active June 5, 2025 16:21
Show Gist options
  • Save alexdlaird/5f9db404292b57da429f88fc1b94f215 to your computer and use it in GitHub Desktop.
Save alexdlaird/5f9db404292b57da429f88fc1b94f215 to your computer and use it in GitHub Desktop.
Simple HTTP server integration example for pyngrok, full documentation found at https://pyngrok.readthedocs.io/en/latest/integrations.html
import os
from http.server import HTTPServer, BaseHTTPRequestHandler
from pyngrok import ngrok
port = os.environ.get("PORT", "80")
server_address = ("", port)
httpd = HTTPServer(server_address, BaseHTTPRequestHandler)
public_url = ngrok.connect(port)
print("ngrok tunnel \"{}\" -> \"http://127.0.0.1:{}/\"".format(public_url, port))
try:
# Block until CTRL-C or some other terminating event
httpd.serve_forever()
except KeyboardInterrupt:
print(" Shutting down server.")
httpd.socket.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment