Skip to content

Commit

Permalink
修复跨域问题(#52
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroi-sora committed Nov 8, 2023
1 parent 652bcdb commit e2329b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions UmiOCR-data/py_src/server/ocr_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def onEnd(msnInfo, msg):
condition.notify()

data = request.json
if not data:
return json.dumps({"code": 800, "data": f"请求为空。"})
if "base64" not in data:
return json.dumps({"code": 801, "data": f"请求中缺少 base64 字段。"})
if "options" not in data:
Expand Down
12 changes: 10 additions & 2 deletions UmiOCR-data/py_src/server/web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@
Host = "127.0.0.1" # 由qml设置


# 设置响应头,允许跨域
# 允许跨域
@UmiWeb.hook("before_request")
def _validate_before():
re_method = request.environ.get("REQUEST_METHOD")
hacrm = request.environ.get("HTTP_ACCESS_CONTROL_REQUEST_METHOD")
if re_method == "OPTIONS" and hacrm:
request.environ["REQUEST_METHOD"] = hacrm


@UmiWeb.hook("after_request")
def _enableCors():
def _validate_after():
response.headers["Access-Control-Allow-Origin"] = "*"
response.headers["Access-Control-Allow-Headers"] = "*"
response.headers["Access-Control-Allow-Methods"] = "GET, POST, PUT, OPTIONS"
Expand Down

0 comments on commit e2329b1

Please sign in to comment.