Hey all.
I have an Angular frontend connecting to a Mezzio API and am having an issue getting my heartbeat endpoint connection working. This is a new backend, and all I’m looking for here is confirmation that my mezzio-cors middleware is setup correctly.
The FE on localhost:4200 and the API is localhost:8080. I’ve tried both localhost and 127 address but the same (Node doesn’t always like localhost).
In my config/autoload/development.local.php I have:
'mezzio-cors' => [
'paths' => [
'/' => ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
'/api/ping' => ['GET', 'OPTIONS']
],
'allowed_origins' => ['http://localhost:4200'],
'allowed_headers' => ['Content-Type'],
'allowed_methods' => ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
'max_age' => 86400,
],
Then in my config/pipeline.php I have:
$cors = $container->get(CorsInterface::class);
$configurationLocator = $container->get(ConfigurationLocatorInterface::class);
$responseFactory = $container->get(ResponseFactory::class);
$corsMiddleware = new CorsMiddleware($cors, $configurationLocator, $responseFactory);
$app->pipe($corsMiddleware);
I have this after the inclusion of the ErrorHandler middleware, but before anything else.
Now when I access the /api/ping endpoint with RESTer or a cURL command line request, I correctly get:
{
status: "online",
time: 1715713902
}
…but when I hit it with my FE app I get net::ERR_FAILED 403 (The origin “http://localhost:4200” is not authorized)
Do you see any obvious issues here?
Thanks for any help.