-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
29 lines (22 loc) · 748 Bytes
/
Copy pathserver.py
File metadata and controls
29 lines (22 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import http.server
import socketserver
import os
import webbrowser
from threading import Timer
# Set the port
PORT = 8000
# Change to the directory containing the HTML files
os.chdir(os.path.dirname(os.path.abspath(__file__)))
# Create the handler
Handler = http.server.SimpleHTTPRequestHandler
# Create the server
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print(f"Server started at http://localhost:{PORT}")
print("Press Ctrl+C to stop the server")
# Open the browser automatically
def open_browser():
webbrowser.open(f"http://localhost:{PORT}/html/index.html")
# Open browser after a short delay
Timer(1.5, open_browser).start()
# Start the server
httpd.serve_forever()