Last active
June 5, 2025 16:21
-
-
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
This file contains hidden or 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
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