I’ve try all way but without success resolve this problem
I have the following API (local) in Laravel
http://127.0.0.1:8000/api/v1/login
I’m using ionic lab
http://localhost:8200/
and show this error
Access to XMLHttpRequest at ‘http://127.0.0.1:8000/api/v1/login’ from origin ‘http://localhost:8100’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
In my service authentication
login(user: User) {
return this.http.post<User>(environment.url + '/login', user)
}
Already input proxie
"proxies": [
{
"path": "/v1",
"proxyUrl": "http://127.0.0.1:8000/api/v1"
}
]
and nothing
already input in CORS in Middleware and nothing
header('Access-Control-Allow-Origin: http://localhost:8100, http://localhost:8200');
header('Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
How to resolve it?
Add in the headers of your http requests the following
1 Like
It looks like the verb for preflight is missing. CORS is only configured on the server. If you change everything to *, it should work with no problem. Once working, you can easily change the configuration to whatever your requirements are.
1 Like
Hey guys, I find one solution its ok, lets go
In my case I did it in Laravel I created a file CorsMiddleware and I input the following code
app > Http > Middleware > CorsMiddleware.php
public function handle($request, Closure $next)
{
if($request->is('api/*') && \App::environment('local')) {
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token, Authorization');
}
return $next($request);
}
the problem was that I had forgotten of to put in Kernel tha class CorsMiddleware like
protected $middleware = [
...
\App\Http\Middleware\CorsMiddleware::class,
];
after to make it in Ionic local work with charm, the integration with Laravel successfully now
obs: in this case, I dont’t needed to put in proxies, I removed it and work normaly