It was six hours, and I still do not get a solution for the next problem.
I am trying to get AngularJS to hit my API from different domains. After searching the Internet, I found this package that says it can "add support for CORS (Cross-Origin Resource Sharing) headers in your Laravel application"
I followed all the instructions. Install this and this to make it work, but still no luck. My server always sends me the same error:
XMLHttpRequest cannot load http: //lab.laracon/v1/lists? Id = 123 & password = whatever & username = OSVC8HKKcvCFrsqXsMcbOVwVQvOL0wr3 . The requested resource does not have an Access-Control-Allow-Origin header. Origin ' http: //lab.angularapi ' is therefore not allowed.
here is my angular code:
var Demo = angular.module( "Demo", [ "ngResource" ] );
Demo.controller(
"ListController"
function( $scope, ,$http, $resource ) {
$http.defaults.useXDomain = true;
$scope.useResource = function() {
var Lists = $resource('http://lab.laracon/v1/lists', {
username: 'OSVC8HKKcvCFrsqXsMcbOVwVQvOL0wr3',
password: 'whatever'
});
Lists.get({
id: 1
}, function(data) {
alert(data.ok);
});
};
}
);
Here is my barryvdh laravel-cors configuration file:
'defaults' => array(
'allow_credentials' => false,
'allow_origin' => array(),
'allow_headers' => array(),
'allow_methods' => array(),
'expose_headers' => array(),
'max_age' => 0,
),
'paths' => array(
'^/v1/' => array(
'allow_origin' => array('*'),
'allow_headers' => array('*'),
'allow_methods' => array('POST', 'PUT', 'GET', 'DELETE', 'OPTIONS'),
'max_age' => 3600,
),
),
and finally here is the nginx server configuration:
location / {
try_files $uri $uri/ /index.php?$query_string;
add_header 'Access-Control-Allow-Origin' 'http://lab.angularapi';
add_header 'Access-Control-Allow-Credentials' 'false';
add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
}
Can anyone help me? what is wrong with my code and configuration? thank