0
Good morning! I am developing a hybrid application using Ionic, when I try to send a post to my server (Windows) error occurs below:
Xmlhttprequest cannot load http://localhost:8000/api/client/order. No 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'http://localhost:8100' is therefore not allowed access.
Here is my service that contains the URL:
angular.module('starter.services')
.factory('Order', ['$resource', 'appConfig',function($resource, appConfig) {
return $resource(appConfig.baseUrl + '/api/client/order/:id', {id: '@id'},{
query: {
isArray: false
}
});
}]);
Cors is enabled in the Laravel, follows my routes where it contains the URL:
Route::group(['middleware' => 'cors'], function(){
Route::post('oauth/access_token', function() {
return Response::json(Authorizer::issueAccessToken());
});
Route::group(['prefix'=>'api', 'middleware'=>'oauth','as'=>'api.'], function(){
Route::group(['prefix'=>'client','middleware'=>'oauth.checkrole:client','as'=>'client.'], function(){
Route::resource('order',
'Api\Client\ClientCheckoutController', [
'except' => ['create', 'edit', 'destroy']
]);
Route::get('products','Api\Client\ClientProductController@index');
});
});
Follows Cors.php file:
<?php
return [
/*
|--------------------------------------------------------------------------
| Laravel CORS
|--------------------------------------------------------------------------
|
| allowedOrigins, allowedHeaders and allowedMethods can be set to array('*')
| to accept any value.
|
*/
'supportsCredentials' => false,
'allowedOrigins' => ['*'],
'allowedHeaders' => ['*'],
'allowedMethods' => ['GET', 'POST', 'PUT', 'DELETE'],
'exposedHeaders' => [],
'maxAge' => 0,
'hosts' => [],
];
Personal thank you.
Actually leaving the Cors middleware on the global upload works on the localhost, but if I leave it only on API routes in production it will work.
– viniciussvl