From my React Frontend I send a request to my Symfony backend.(Previously it worked fine with a pure PHP backend) .
useEffect(() => {
axios.get('http://localhost:8080/real_estate_refactored_backend/main').then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error.message);
});
});
The main in the URL is the route of my Symfony controller
<?php
namespace App\Controller;
use App\Entity\Estates;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class MainController extends AbstractController
{
/**
* @Route("/main", name="main")
*/
public function index(): Response
{
$entityManager = $this->getDoctrine()->getManager();
$estates = $entityManager->getRepository(Estates::class)->findAll();
$response = new Response();
$response->setContent(json_encode([
'estates' => uniqid(),
]));
$response->headers->set('Content-Type', 'application/json');
$response->headers->set('Access-Control-Allow-Origin', '*');
return new Response($response);
}
}
In Symfony the connection with the database went fine.
And eventhough I have installed the Nelmino CORS bundle in Symfony with the following configuration in the
nelmino_cors.yaml
nelmio_cors:
defaults:
origin_regex: true
allow_origin: ['*']
allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
allow_headers: ['*']
expose_headers: ['Link']
max_age: 3600
paths:
'^/': null
I still get the following error message
What can I do?

'^/': ~?