AH i found the issue. My endpoint was not returning anything so I added return response([]);
Not sure why that would cause the cors issue though.
I created a middleware class to handle cors for me:
$app->middleware([
App\Http\Middleware\CorsMiddleware::class,
]);
That class above looks somewhat like this:
class CorsMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
var_dump(1);die;
......
Now when I do a request, i do not see the var_dump(). Is it not being run?
I am trying to solve this cors issue:
Access to fetch at 'http://localhost:8000/feedback/add' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
By doing this: https://www.codementor.io/@chiemelachinedum/steps-to-enable-cors-on-a-lumen-api-backend-e5a0s1ecx
Also it seems when I go directly to: http://localhost:8000/feedback/add in my browser, then It seems to work fine. I see the vardump
Any ideas?
AH i found the issue. My endpoint was not returning anything so I added return response([]);
Not sure why that would cause the cors issue though.
Please or to participate in this conversation.