Add CORS support to the API (#2718)

This commit is contained in:
rizerphe 2023-06-24 16:16:06 +03:00 committed by GitHub
parent 8c36c19218
commit 77baf43f6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -184,6 +184,17 @@ class Handler(BaseHTTPRequestHandler):
else: else:
self.send_error(404) self.send_error(404)
def do_OPTIONS(self):
self.send_response(200)
self.end_headers()
def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', '*')
self.send_header('Access-Control-Allow-Headers', '*')
self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate')
super().end_headers()
def _run_server(port: int, share: bool = False): def _run_server(port: int, share: bool = False):
address = '0.0.0.0' if shared.args.listen else '127.0.0.1' address = '0.0.0.0' if shared.args.listen else '127.0.0.1'