使用angularjs客户端应用程序和提供api的烧瓶应用程序启动新项目.我正在使用mongodb作为数据库.我不得不立即排除jsonp,因为我需要能够跨不同端口进行POST.所以我们有localhost:9000用于角度应用程序,localhost:9001用于烧瓶app.
我经历了我的API以及我的角度文件中的CORS所需的更改.见下面的来源.我遇到的第一个问题是,有一个错误,CORS允许标头无法识别Chrome中的localhost.我更新了我的hosts文件,所以我可以使用moneybooks.dev,这适用于我的GET请求而不使用JSONP.
现在,我面临的问题.提交POST请求时,它的说明Origin http://moneybooks.dev:9000 is not allowed by Access-Control-Allow-Origin是什么?GET可以通过,但POST被拒绝.我看到请求来到烧瓶,但它返回HTTP 400.我需要帮助使POST请求工作.
另一个可能相关的问题是,在我的GET请求中,有时GET请求根本不会触发.就像在BudgetCtrlloadBudget函数中一样.在#/ budgetgets/budgetID上,预算名称有时根本不会加载.我检查烧瓶日志,但没有看到请求通过.然后我点击刷新,我看到请求,预算名称出现在页面上但是在烧瓶日志中我看到一个错误.[Errno 10053] An established connection was aborted by the software in your host machine.它是一个连接错误,只有在GET请求成功时才会出现在烧瓶日志中.
这些问题是否相关?谁能看到我做错了什么?
app.js
'use strict';
angular.module('MoneybooksApp', ['ui.bootstrap', 'ngResource'])
.config(['$routeProvider', '$httpProvider', function ($routeProvider, $httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.otherwise({
redirectTo: '/'
});
}]);
Run Code Online (Sandbox Code Playgroud)
budgets.js
'use strict';
angular.module('MoneybooksApp')
.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/budgets', {
templateUrl: 'views/budgets-list.html',
controller: 'BudgetListCtrl'
})
.when('/budgets/:budgetID', { …Run Code Online (Sandbox Code Playgroud)