I have useing laravel and angular application but on some system i'm still getting this CORS error
Access to XMLHttpRequest at from origin has been blocked by CORS policy Response to preflight request does'nt pass access control check : No Access Control Allow Origin header is present on the requested resource
at the same time if i'm checking on some other system it is working. But i want to resolve this issue permanently.
I'm using these packages :
composer.json
"php": "^7.3|^8.0",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.65",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5",
"tymon/jwt-auth": "^1.0"
CORS Muiddleware :
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Closure;
class CORS {
public function handle(Request $request, Closure $next)
{
$response = $next($request);
$response->header('Access-Control-Allow-Origin', '*')->header('Access-Control-Allow-Headers', 'Content-type, X-Auth-Token, Authorization, Origin');
return $response;
}
}
api
Route::group(['middleware' => ['api','cors'],'prefix' => 'auth'], function ($router) {
Route::post('/login', [AuthController::class, 'login']);
Route::post('/register', [AuthController::class, 'register']);
Route::post('/logout', [AuthController::class, 'logout']);
Route::post('/refresh', [AuthController::class, 'refresh']);
Route::get('/user-profile', [AuthController::class, 'userProfile']);
});
Any suggestion Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire