I am making simple todo app, with Symfony 4 in the back-end and Vue.js for front-end.
I am getting a 405
error status for unknown reasons since a few other endpoints are working correctly.
Here is part of my listController
:
/**
* @return \FOS\RestBundle\View\View
*/
public function getListsAction()
{
$data = $this->taskListRepository->findAll();
return $this->view($data, Response::HTTP_OK);
}
/**
* @Rest\RequestParam(name="title", description="Title of the list", nullable=false)
* @param ParamFetcher $paramFetcher
* @return \FOS\RestBundle\View\View
*/
public function postListsAction(ParamFetcher $paramFetcher)
{
$title = $paramFetcher->get('title');
if ($title) {
$list = new TaskList();
$preferences = new Preference();
$preferences->setList($list);
$list->setPreferences($preferences);
$list->setTitle($title);
$this->entityManager->persist($list);
$this->entityManager->flush();
return $this->view($list, Response::HTTP_CREATED);
}
return $this->view(['title' => 'This cannot be null'], Response::HTTP_BAD_REQUEST);
}
the get action is working correctly here it allows me to get all lists from db
and nelmio_cors.yaml
file:
nelmio_cors:
defaults:
origin_regex: true
allow_credentials: true
allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
allow_methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']
allow_headers: ['Content-Type', 'Authorization', 'origin', 'Accept', 'bearer', 'Allow']
expose_headers: ['Link']
max_age: 3600
paths:
'^/': ~
as you can see POST method is allowed.
as shown the method occurs under expected method and endpoint, register and login_check, where method is not specified working correctly with using POST
Network error:
and in console I am getting CORS error.