Spaces:
Running
Running
File size: 466 Bytes
6a7997c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
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()
|