Solve Cross Origin Resource Sharing with Flask
It worked like a champ, after bit modification to your code
# initialization
app = Flask(__name__)
app.config['SECRET_KEY'] = 'the quick brown fox jumps over the lazy dog'
app.config['CORS_HEADERS'] = 'Content-Type'
cors = CORS(app, resources={r"/foo": {"origins": "http://localhost:port"}})
@app.route('/foo', methods=['POST'])
@cross_origin(origin='localhost',headers=['Content- Type','Authorization'])
def foo():
return request.json['inputVar']
if __name__ == '__main__':
app.run()
I replaced * by localhost. Since as I read in many blogs and posts, you should allow access for specific domain
Flask:XMLHttpRequest at '...' from origin has been blocked by CORS policy No 'Access-Control-Allow-Origin' header is present on the requested resource
i found a solution, the problem was not my python code it was my java code :/
a simple add of " transports: ["polling"] " solve the problem
import io from "socket.io-client";
let endPoint = "http://localhost:5000";
let socket = io.connect(`${endPoint}`, { transports: ["polling"] });
function receiveData(cb) {
socket.on("receivedData", (resp) => cb(resp));
}
export { receiveData };
Related Topics
How to Make 'Setinterval' Behave More in Sync, or How to Use 'Settimeout' Instead
Settimeout/Cleartimeout Problems
Put JavaScript in One .Js File or Break It Out into Multiple .Js Files
JavaScript Custom Event Listener
Function to Calculate Distance Between Two Coordinates
Copy a Variable's Value into Another
How to Trigger a Bootstrap Modal Programmatically
Jquery Clone Form Fields and Increment Id
How to Split a String into an Array of Characters
Getting a Unhandledpromiserejectionwarning When Testing Using Mocha/Chai
Unsafe JavaScript Attempt to Access Frame with Url
How to Access Parent Window Object Using Jquery
Preventing Click Event with Jquery Drag and Drop
Node.Js Async/Await Using with MySQL
Understanding JavaScript Scope with "Var That = This"
Passing Variables to the Next Middleware Using Next() in Express.Js
How to Ungzip (Decompress) a Nodejs Request's Module Gzip Response Body