You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I left a comment in #289 but was told that "This issue must be closed now", I can only interpreter that as I should open a new issue :)
I have of course tried everything in that thread but it didn't help me resolve my issue.
I have assembled a reproduction case below. In the console that is running flask I don't get any relevant logs and the website is saying Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1/api/v1/test. (Reason: CORS request did not succeed). Status code: (null).
Can someone see if there is something wrong with my general setup or if flask-cors simply doesn't work with the kind of setup I am trying to accomplish?
fromflaskimportFlaskfromflask_corsimportCORSfromflask_restximportNamespace, Resource, Apifromflaskimportjsonify, make_responsefromflaskimportBlueprint, render_template_stringimportlogginglogging.basicConfig()
LOGGER=logging.getLogger("reprod-case")
LOGGER.setLevel(logging.DEBUG)
LOGGER.info("Created LOGGER")
logging.getLogger('flask_cors').level=logging.DEBUG# Create the restx namespace with a specified pathns=Namespace(name='api_v1', path="/api/v1")
@ns.route('/test')classDeck(Resource):
defget(self):
print("get")
returnmake_response(jsonify({"message": "You did a Get!"}), 200)
defput(self):
print("Put")
returnNone, 201html_page="""<html lang="en"><body><button type="submit" name="myButton" value="Value">Click Me</button><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script><script>$(document).ready(function() { $('button').on('click',function(e){ const vote_value = e.currentTarget.attributes.value.value; console.log() $.ajax({ type: 'GET', crossDomain: true, withCredentials: true, url: 'http://127.0.0.1/api/v1/test', contentType: 'application/json' }) });});</script></body></html>"""# Blueprint for the webpage and add a routebp=Blueprint("/", __name__)
@bp.route('/')defhome_route():
returnrender_template_string(html_page)
# Setup the app, Cors, add the namespace and blueprintdefcreate_app():
app=Flask(__name__)
# CORS(app, resources={r"/api/*": {"origins": "*"}},CORS(app,
resources={r"/api/*": {"origins": ['http://192.168.50.16:5000', 'http://localhost:5000']}},
supports_credentials=True
)
api=Api(doc="/api/", title="Endpoints")
api.add_namespace(ns, path="/api/v1")
app.register_blueprint(bp)
api.init_app(app)
returnappif__name__=="__main__":
app_=create_app()
app_.run(debug=True)
The text was updated successfully, but these errors were encountered:
I left a comment in #289 but was told that "This issue must be closed now", I can only interpreter that as I should open a new issue :)
I have of course tried everything in that thread but it didn't help me resolve my issue.
I have assembled a reproduction case below. In the console that is running flask I don't get any relevant logs and the website is saying
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1/api/v1/test. (Reason: CORS request did not succeed). Status code: (null).
Can someone see if there is something wrong with my general setup or if
flask-cors
simply doesn't work with the kind of setup I am trying to accomplish?The text was updated successfully, but these errors were encountered: