|
#!/usr/bin/env python3
|
|
import http.server
|
|
import socketserver
|
|
import os
|
|
import sys
|
|
from urllib.parse import unquote
|
|
|
|
class CustomHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
|
|
def do_GET(self):
|
|
# If requesting root path, serve the project HTML file
|
|
if self.path == '/' or self.path == '':
|
|
# Find the project HTML file (assumes pattern: projectname.html)
|
|
html_files = [f for f in os.listdir('.') if f.endswith('.html') and not f.startswith('index')]
|
|
if html_files:
|
|
self.path = '/' + html_files[0]
|
|
else:
|
|
# Fallback to index.html if it exists
|
|
self.path = '/index.html'
|
|
|
|
return super().do_GET()
|
|
|
|
if __name__ == "__main__":
|
|
port = int(sys.argv[1]) if len(sys.argv) > 1 else 5245
|
|
|
|
with socketserver.TCPServer(("", port), CustomHTTPRequestHandler) as httpd:
|
|
print(f"Starting HTTP server at http://localhost:{port}")
|
|
print(f"Serving directory: {os.getcwd()}")
|
|
try:
|
|
httpd.serve_forever()
|
|
except KeyboardInterrupt:
|
|
print("\nServer stopped.")
|