Last active
April 23, 2022 05:31
-
-
Save Breta01/e010a2cdeae3ef9033753c554aacefbd to your computer and use it in GitHub Desktop.
File server with smart contracts deployment
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
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