Tag: cors

sailsjs cors坏请求仍然通过控制器

所以我的cors.js文件看起来像 module.exports.cors = { allRoutes: true, origin: require('./local.js').hosts, // this is 'http://localhost' } 然后,我select了一个随机的网站来请求,在这种情况下: http : //tools.pingdom.com/fpt/ 这是我的要求和页面的响应 $ .post(' http:// localhost:1337 / gift / create ')Object {readyState:1,getResponseHeader:function,getAllResponseHeaders:function,setRequestHeader:function,overrideMimeType:function …} jquery-2.1.1.min.js :4 POST http:// localhost:1337 / gift / create (index):1 XMLHttpRequest无法加载http:// localhost:1337 / gift / create 。 “Access-Control-Allow-Origin”标题包含无效值“'。 Origin'http: //tools.pingdom.com '因此不被允许访问。 但是,我仍然在控制台中获取错误,因为控制器function仍然被调用。 sails> error: Sending 500 […]

启用CORS for PouchDB以使用CouchDB

按照这个教程: http : //pouchdb.com/guides/setup-couchdb.html ,我能够安装CouchDB并设置它,然后我安装了Node.js,以便能够使用npm来设置CORS ,但是当我做了我得到了以下错误:'错误:EACCES,mkdir'/ usr / local / lib / node_modules / add-cors-to-couchdb'…请尝试以root用户身份重新运行此命令。 。不好的代码0' 任何帮助?

CORS问题:“Access-Control-Allow-Origin”标题不得包含多个值

我想允许我的服务器让两个不同的域读取数据而不会得到CORS问题。 因此,我写了下面的代码行(在node.js中): app.use(function(req, res, next){ res.header("Access-Control-Allow-Origin", ["http://ServerA:3000", "http://ServerB:3000"]); res.header("Access-Control-Allow-Headers", "*"); next(); }); 但是,当我通过浏览器发送请求时,我得到了错误: “Access-Control-Allow-Origin”头包含多个值“ http:// ServerA:3000 , http:// ServerB:3000 ”,但只允许有一个值。 原因' http:// ServerB:3000 '因此不被允许访问。 我的问题是如何为多个来源定义“Access-Control-Allow-Origin”。 我不想用'*',因为它太自由了。

在使用AngularJS发送GET请求时,无法从WebStorm IDE执行“打开”无效URL

我启用了CORS模块并在我的nodeJS服务器代码中设置了必需的选项。 我能够从我的浏览器发送GET请求到给定的URL并获得响应。 但是当我试图执行下面的代码发送一个GET请求使用WebStorm IDE的内置服务器的以下AngularJS代码时,我得到以下错误。 city name Delhi error SyntaxError: Failed to execute 'open' on 'XMLHttpRequest': Invalid URL 代码如下。 mainApp.controller('dController', function($scope,$http) { this.ccaid = { city:'', circle:'', area:'', }; this.getCircle=function(){ console.log('city name ' + this.ccaid.city); $http({ method: 'GET', crossDomain:true, url: 'xx.xxx.xx.xx:3000/fetchCityArea', params:{city:this.ccaid.city} }).then(function(success){ console.log('response ' + success); },function(error){ console.log('error ' + error); }); }; }); URL没有问题,但仍然无法发送GET请求。 […]

为什么当我根据DynDNS url名称进行axios请求而不是IP时,会出现CORS错误?

我有一个运行Node.js的树莓。 CORS被安装和configuration。 我设置了端口转发,但由于IP不断变化,我在DynDNS提供商注册。 我使用Axios的React.js来处理localhost:8080上的API请求。 有趣的是,如果我根据我的要求(例如) const ROOT_URL = 'http://81.23.563.80:5000/'; 每24小时不断变化,CORS模块正在完成工作,我可以执行我的请求。 但是,如果我想做对,并提出我的要求 const ROOT_URL = 'http://mydyndnsurl.provider.com/'; 那么我会得到他典型的错误信息: XMLHttpRequest无法加载http://mydyndnsurl.provider.com/ 。 对预检请求的响应不会通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。 原因' http:// localhost:8080 '因此不被允许访问。 有没有人有这个问题的解决scheme?

在angular度全堆发生器上启用CORS?

好吧,我有一个EC2实例启动并运行nodeJs,并表示我正在使用生成器的香草安装,我的app.js文件如下所示: /** * Main application file */ 'use strict'; // Set default node environment to development process.env.NODE_ENV = process.env.NODE_ENV || 'development'; var express = require('express'); var mongoose = require('mongoose'); var config = require('./config/environment'); // Connect to database mongoose.connect(config.mongo.uri, config.mongo.options); // Populate DB with sample data //require('./config/seed'); // Setup server var app = express(); var server […]

在2个端口上使用node rest api和angularJS应用程序的CORS问题

我有我的angularJS应用程序(在本地主机:9000)的古典CORS问题试图赶上我的节点服务器(在本地主机:9001) 这里我的restapi(app.js)代码: var cors = require('cors'); app.use(cors()); app.options('*', cors()); app.all('/*', function(req, res, next) { // CORS headers res.header("Access-Control-Allow-Origin", "*"); res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); res.header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type"); if (req.method == 'OPTIONS') { res.status(200); res.write("Allow: GET,PUT,POST,DELETE,OPTIONS"); res.end(); } else { next(); } }); 正如你所看到的,我尝试过这些解决scheme是徒劳的: Node.js和AngularJS中的CORS 当restAPI应用程序服务器(express)和Angulars js应用程序运行在不同的端口时,Cors问题 这里是webapp中简单的$ http调用: var req = { method: 'GET', url: 'localhost:9001/memories' }; $http(req). […]

与Express.js和Angular2的CORS

我试图从我的远程Express.js服务器下载一个PLY文件到我的Angular / Ionic应用程序。 我现在在Amazon AWS上托pipe我的Ionic应用程序。 这是Ionic应用程序的Typescript: //this.currentPlyFile encompasses entire URL document.getElementById('entity').setAttribute("ply-model", "src: url(" + this.currentPlyFile + ".ply);"); 我的Express.js服务器中有以下内容: app.use(function(req, res, next) { res.header('Access-Control-Allow-Credentials', true); res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Methods', 'GET,POST'); res.header('Access-Control-Allow-Headers', 'appid, X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept'); if ('OPTIONS' == req.method) { res.send(200); } else { next(); } }); 但是在请求PLY文件时出现以下错误: XMLHttpRequest cannot load "my url here" No 'Access-Control-Allow-Origin' […]

如何在交叉源请求中保留会话数据?

我是使用Express和Connect的新手,所以我希望我做一些简单的解决scheme愚蠢的东西… 基本上,我有一个用户使用Personalogin的页面。 为了validation身份validation尝试,我使用express-persona 。 假设这个模块将用户的validation邮件地址保存在一个会话variables(req.session.email,默认)中。 现在,login后,用户可以发表评论,这个评论将与用户login的电子邮件地址一起保存。当服务表单的服务器与处理发表评论的服务器相同时,这工作正常。 然而,当它们不同时(比如说用户填写http://localhost:8001的表单,而浏览器则发送一个POST请求到http://localhost:8000这个应该保存注释),所有的突然req.session.email值是undefined 。 我认为我正确设置了跨源资源共享。 表单是这样发送的(使用jQuery): $.ajax('http://localhost:8000/post/comment', { data: {comment: $('#commentField').val()}, type: 'POST', xhrFields: {withCredentials: true} } ); (注意xhrField: {withCredentials: true} – 会话cookie被传递,我通过检查networking请求来validation。) 服务器设置(我认为)正确的CORS标题: res.header('Access-Control-Allow-Origin', 'http://localhost:8001'); res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With'); res.header('Access-Control-Allow-Credentials', 'true'); 当我添加console.log(req.cookie) ,我看到sessionId cookie与POST请求一起发送的值相同。 但是: console.log(req.session.email)显示undefined的跨源请求 – 再一次,当请求来自同一个来源时,它工作正常。 我究竟做错了什么?

cross domain CORS支持backbone.js

我正在尝试为我的骨干应用程序实施一个跨域设置。 我的服务器(express.js)允许跨域和凭证: var allowCrossDomain = function(req, res, next) { var allowedHost = [ 'http://localhost:3001', 'http://localhost:7357' ]; if(allowedHost.indexOf(req.headers.origin) !== -1) { res.header('Access-Control-Allow-Credentials', true); res.header('Access-Control-Allow-Origin', req.headers.origin) res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); res.header('Access-Control-Allow-Headers', 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version'); next(); } else { res.send({auth: false}); } } app.configure(function(){ …. app.use(allowCrossDomain); …. }); 我的客户端(backbone.js)被configuration为接受跨域: define(["backbone", "jquery", "underscore"], function (BB, […]