[英]flask-cors not sending preflight CORS request
I want to allow only localhost as access-control-allow-origin in my Flask app.我想在我的 Flask 应用程序中只允许 localhost 作为 access-control-allow-origin 。 I tried searching for this issue at other places with no solution.
我尝试在其他地方搜索此问题但没有解决方案。 My code is very simple and straightforward as follows :
我的代码非常简单明了,如下所示:
from flask import Flask
from routes.routes import *
from flask_cors import CORS
app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "http://localhost:3000"}})
app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix='/drax')
app.add_url_rule('/template/<actionId>/<actionName>', None, templateActions, methods=['GET'])
The above should ONLY allow any request from localhost:3000 and not from anywhere else, like localhost:8080.以上应该只允许来自 localhost:3000 的任何请求,而不是来自其他任何地方的请求,例如 localhost:8080。 But even when I make the request from port 8080 (another web app), it allows the request.
但即使我从端口 8080(另一个 Web 应用程序)发出请求,它也允许请求。
Looks like you need to specify a valid http origin in your request as under:看起来您需要在请求中指定一个有效的 http 源,如下所示:
CORS(
app,
supports_credentials=True,
resources={
r"/*": {
"origins": [
"http://localhost:3000",
""http://localhost"
"http://127.0.0.1:3000",
"http://127.0.0.1,
]
}
},
)
I do not think http://local is a valid origin我不认为http://local是一个有效的来源
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.