From 77baf43f6d8f13e4cf9fe0f546c9ca1945107458 Mon Sep 17 00:00:00 2001 From: rizerphe <44440399+rizerphe@users.noreply.github.com> Date: Sat, 24 Jun 2023 16:16:06 +0300 Subject: [PATCH] Add CORS support to the API (#2718) --- extensions/api/blocking_api.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/extensions/api/blocking_api.py b/extensions/api/blocking_api.py index 25f228a5..e84e68e2 100644 --- a/extensions/api/blocking_api.py +++ b/extensions/api/blocking_api.py @@ -184,6 +184,17 @@ class Handler(BaseHTTPRequestHandler): else: 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): address = '0.0.0.0' if shared.args.listen else '127.0.0.1'