lately I've been creating a Client for a REST API using Angular and $resource. Here a simple example.
resources.factory('Type', ['$resource', '$http', function($resource, $http) {
return = $resource(
'http://api.lelylan.com/types/:id',
{ id: '@id' },
{ update: { method: 'PUT' } });
}]);
Everything works jut fine in local and with the test suite, but I get a problem when making the request to the API running on Heroku (a cloud application platform). The URI (you can check it also by putting it on your browser) is this [1].
<h1>Client HTTP request</h1>
<div ng-controller="TypeController">
<div>Type name is {{type.name}}</div>
</div>
</hr>
<script>
function TypeController($scope, Type) {
$scope.type = Type.get({ id: '50ffa785a90db269f2000002' });
}
</script>
The problem is that using CORS, when Chrome (actually all webkit based browsers) makes an OPTION request, the browser does not set a Content-Length for it. Heroku, which is based on Nginx (HTTP and reverse proxy server) always gives back a 411 (Length Required) error when the content length is not set.
I've also tried to force it by setting the Header as a common Header for a request, but JS does not allow this header to be set for safety reasons. I'm stuck. Can you give me any hint about this?
Thanks a lot.
[1] http://api.lelylan.com/types/50ffa785a90db269f2000002.
UPDATE 1
Here you can see the message I get from Heroku logs. I'm using Stack cedar and Ruby/Rails as framework. From the browser I get this error.
OPTIONS http://api.lelylan.com/devices/50c61ff1d033a9b610000001 411 (Length Required)