Laravel Cors (Middleware NOT working)

后端 未结 8 1577
孤独总比滥情好
孤独总比滥情好 2020-12-31 12:37

I recently tries enabling CORS in Laravel 5.4 but unfortunately it doesn\'t want to work. I have included the code and the error that it\'s giving me below. Can anyone help

8条回答
  •  误落风尘
    2020-12-31 13:14

    I ran into a sudden CORS issue recently that was not caused by CORS header configuration, I discovered the following:

    There are Red Herring scenarios that can also cause a CORS Cross Origin error to display and yet not have anything to do with CORS configuration, It is a result of when CORS is handled by middleware and something else prevents it from being triggered.

    The following can indirectly cause the error to display in a browser response:

    • A PHP error in a Middleware class.
    • return $next($request); not being fired in middleware class method handle.
    • Route::middleware in web or api router configs reference a middleware that no longer exists or is miss spelt.
    • Same as above point but middleware specified in a Controller with $this->middleware();

    Any of these can prevent a Cors middleware from ever being fired because the app exits too early and never sets the headers and thus results in a CORS error instead of a 500 Server Header error as a result of bad middleware files or bad references to middleware.

    If you are certain you have configured CORS correctly then you should check your PHP error logs for Middleware errors.

提交回复
热议问题