i create a api which return the list of users.i test it in postman app and working fine (return json) . but when i try to call it in ionic2 then it show me error in console.i try to insert
header('Access-Control-Allow-Origin: *');
in public/index.php at the top . and also try to make a middleware and the handler() has following code
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
route/api.php
Route::group(['middleware' => ['Cors']] ,function(){
Route::get('/nearby',['as' => 'people.nearby' , 'uses' => function(){
return User::all();
}]);
});
and inside kernel.php($routeMiddleware) i add alliance as 'Cors' => \App\Http\Middleware\Cors::class
i try to call a test api link(https://randomuser.me/api/) from the google to check if my js or typescript code is working fine and i got the response with json but got error of Allow Access Origin while calling my laravel api . where i am going wrong or some error in my code . any help will appreciated.
Here is the request result of api from network tab(Developer mode).