cors error code example
Example 1: cors error in flask
from flask import Flask
from flask_cors import CORS, cross_origin
app = Flask(__name__)
CORS(app)
@app.route("/")
def helloWorld():
return "Hello world"
Example 2: nock CORS error
fetchNockProject = nock($API)
.defaultReplyHeaders({ 'access-control-allow-origin': '*' })
.get('/projects/1')
.reply('200', project);
Example 3: allow cross origin
Access-Control-Allow-Origin: *
Access-Control-Allow-Origin: <origin>
Access-Control-Allow-Origin: null
Example 4: javascript cors error
$.ajax({
headers: { "Accept": "application/json"},
type: 'GET',
url: 'http://cl.ly/2wr4',
crossDomain: true,
beforeSend: function(xhr){
xhr.withCredentials = true;
},
success: function(data, textStatus, request){
console.log(data);
}
});