angularjsstudent angularjsstudent - 5 months ago 24
Node.js Question

AngularJS + ServiceStack + Node.js as a proxxy?

I have created an application in angularjs. The server side is covered by servicestack, I'd like to process a json file that is provided by the servicestack application. To do it I use following code in angularjs:

taskListApp.factory('Fact', function ($resource) {
return $resource("http://localhost:55267/hello?format=json", {},
{
query: {method: 'GET', url: "http://localhost:55267/hello?format=json"},
});
});


However I get the error in console about same origin policy, missing CORS header.

I'm trying to use the default node.js template to create a proxxy server, but I'm clueless about what ports should I use. Any headers?

EDIT:
this is my node.js code, which returns unhandled 'error' error

httpProxy.createServer({
target:'http://localhost:55267'
}).listen(8003);

http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(55267);

Answer

Not sure if this will resolve the issue with node but if you want to add CORS Response Headers to the ServiceStack response you need to register the CORS plugin in your AppHost's Configure():

Plugins.Add(new CorsFeature());