If I use the same origin on front and back end, then my cors middleware is hit. But with different origins, it seems that the cors is blocked before reaching my own cors middleware...
Dec 6, 2019
5
Level 3
assign middleware to only api group
The laravel doc is unclear on how to assign a middleware to only a group.
Here a "cors" middleware in Kernel.php:
'api' => [
'throttle:60,1',
'bindings',
'cors'
],
];
protected $routeMiddleware = [
//...
'cors' => Cors::class
];
Using this, my api route (in "routes/api.php") does not trigger my cors middleware.
It only works if I use it globally in protected $middleware = []
My api route is supposed to use the "api" group. Why my "cors" middleware is not triggered ?
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
Please or to participate in this conversation.