Nodejs http://test.dev:3000/api/profile。 没有'Access-Control-Allow-Origin'标题Origin'http:// localhost:9000'

NodeJS – Angularjs

CORS问题。

我有问题与REST POST到nodeJS。 REST GET似乎工作正常。

我看到了典型的消息,我似乎无法修复它。

XMLHttpRequest无法加载http://test.dev:3000/api/profile 。 请求的资源上没有“Access-Control-Allow-Origin”标题。 原因' http:// localhost:9000 '因此不被允许访问。 该响应具有HTTP状态码400。

NodeJS – 我有以下设置在我的app.js

var cors = require('cors') app.use(cors()); // Enables CORS var enableCORS = function(req, res, next) { res.header('Access-Control-Allow-Origin', '*'); 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'); // intercept OPTIONS method if ('OPTIONS' == req.method) { // res.send(200); res.sendStatus(200); } else { next(); } }; // enable CORS! app.use(enableCORS); //-------------- 

服务器日志:OPTIONS / api / profile 204 1.257 ms – – POST / api / profile 400 65.141 ms – 698

NodeJS – 路由

 // get email sent - Sept 12, 2015 router.post('/profile', function (req, res, next) { console.log('api: -- start profile update -- auth server '); console.log('api: -- parms --->> ', req.params); console.log('api: -- body --->> ', req.body); console.log('api: -- body.test --->> ', req.body.test); //var updatedColumns = req.body.updatedColumns; ... res.status(200).jsonp({ok: 'ok' }); }); 

Angularjs方..

 service angular.module('testApp').factory('ProfileUpdateService', ['$resource', function($resource) { return $resource('http://test.dev:3000/api/profile'); }]); controller ProfileUpdateService.save('test data', function(data){ console.log('called save on ProfileUpdateService'); }); 

固定。 它看起来像我有几个使用corsfilter。