-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
executable file
·52 lines (43 loc) · 1.94 KB
/
Copy pathserver.py
File metadata and controls
executable file
·52 lines (43 loc) · 1.94 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
"""
Simple HTTP server for Dithering Studio
Run with: python3 server.py
"""
import http.server
import socketserver
import webbrowser
import os
PORT = 3000
class MyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def end_headers(self):
# Add CORS headers
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
self.send_header('Access-Control-Allow-Headers', 'Content-Type')
super().end_headers()
def main():
# Change to the directory where this script is located
os.chdir(os.path.dirname(os.path.abspath(__file__)))
handler = MyHTTPRequestHandler
with socketserver.TCPServer(("", PORT), handler) as httpd:
print(f"""
╔═══════════════════════════════════════════════════╗
║ 🎨 Dithering Studio Server 🎨 ║
╠═══════════════════════════════════════════════════╣
║ ║
║ Server running at: ║
║ → http://localhost:{PORT} ║
║ ║
║ Press Ctrl+C to stop the server ║
║ ║
╚═══════════════════════════════════════════════════╝
""")
# Open browser automatically
webbrowser.open(f'http://localhost:{PORT}')
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\n\n👋 Server stopped. Goodbye!")
httpd.shutdown()
if __name__ == "__main__":
main()