Skip to content

Instantly share code, notes, and snippets.

@Breta01
Last active April 23, 2022 05:31
Show Gist options
  • Save Breta01/e010a2cdeae3ef9033753c554aacefbd to your computer and use it in GitHub Desktop.
Save Breta01/e010a2cdeae3ef9033753c554aacefbd to your computer and use it in GitHub Desktop.
File server with smart contracts deployment
import http.server
from pathlib import Path
# Get root directory
ROOT = Path(__file__).parent.parent
# Class for serving build directory
class Handler(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
# IT'S IMPORTANT TO SET CORRECT DEPLOYMENT PATH HERE:
super().__init__(*args, directory=str(ROOT / "build/deployments"), **kwargs)
# Main function which runs the server
def server_build_directory(port=8100):
with http.server.HTTPServer(("", 8100), Handler) as httpd:
print(f"Server started at http://localhost:{port}")
print("You can stop the server using Ctrl+C")
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("Server stopped.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment