-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
32 lines (27 loc) · 1.03 KB
/
server.py
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
from http.server import HTTPServer, SimpleHTTPRequestHandler
import os
import sys
class CORSRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', 'GET')
self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate')
return super().end_headers()
def do_OPTIONS(self):
self.send_response(200)
self.end_headers()
def run(port=8888):
# Change to the directory containing the script
os.chdir(os.path.dirname(os.path.abspath(__file__)))
server_address = ('', port)
httpd = HTTPServer(server_address, CORSRequestHandler)
print(f'Starting server on port {port}...')
print(f'Test page available at: http://localhost:{port}/extension/test-extension.html')
try:
httpd.serve_forever()
except KeyboardInterrupt:
print('\nShutting down server...')
httpd.server_close()
sys.exit(0)
if __name__ == '__main__':
run()