Spaces:
Running
Running
import http.server | |
import socketserver | |
import os | |
# Define the port Spaces expects applications to run on | |
PORT = int(os.environ.get("PORT", 7860)) | |
DIRECTORY = "." | |
class Handler(http.server.SimpleHTTPRequestHandler): | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, directory=DIRECTORY, **kwargs) | |
with socketserver.TCPServer(("", PORT), Handler) as httpd: | |
print(f"Serving directory {DIRECTORY} at port {PORT}") | |
httpd.serve_forever() | |