baidu / baidu/amis

后端已经处理了CORS问题,前端发送请求也可以正确的收到后端返回的内容但是,前端依旧报CORS error

Open
#7,789 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
18.9k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

#### 实现场景:
我通过FLASK框架作为后端,但是这样会存在一个跨域问题,我在后端中正确的处理了这个问题前端发送请求后端也可以正确的返回内容,但是浏览器依旧返回CORS错误
![image](https://github.com/baidu/amis/assets/76473378/25eee848-903d-4e6d-acce-db752caa4275)
![image](https://github.com/baidu/amis/assets/76473378/1c8937c1-fb9c-4b91-b28c-b937280033ae)

```
# 处理 CORS 预检请求
@app.route('/api', methods=['OPTIONS'])
def handle_preflight():
response = app.make_default_options_response()
response.headers['Access-Control-Allow-Origin'] = 'http://192.168.2.4' # 允许指定的域名跨域访问
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE' # 允许的方法列表
response.headers['Access-Control-Allow-Headers'] = 'Content-Type' # 允许的头部
return response
```

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue identifies a Flask OPTIONS handler and screenshots, but no repository file, test, or entry point. Start by reproducing the browser request with the shown Flask setup and comparing the preflight and response headers with the reported error. Done would require a confirmed repository-side fix or documented limitation, but the issue does not define which.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
api, backend, frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.