jeudi 24 décembre 2015

Forge! Why can't I connect via SSH

I have a laravel application which I've created various api's and they sit awaiting my applications to post / get.

I am developing a ionic app which utilizes Ngresource and sends the post request, however on testing I get the following error:

XMLHttpRequest cannot load http://IPADDRESS/api/test Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.

I have tried on my laravel application wrapping my api routes in a middleware group which includes the middleware CORS. I have also registered the middleware in my Kernel.php file. see below cors middleware.

<?php namespace App\Http\Middleware;
use Closure;

use Illuminate\Contracts\Routing\Middleware;
use Illuminate\Http\Response;

class CORS implements Middleware {

 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
  return $next($request)->header('Access-Control-Allow-Origin' , '*')
          ->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')
          ->header('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, X-Requested-With');
 }
}

but this has made no difference and I get the same error.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire