nelmio / NelmioCorsBundle

Adds CORS (Cross-Origin Resource Sharing) headers support in your Symfony application
https://symfony.com/bundles/NelmioCorsBundle/
MIT License
1.89k stars 108 forks source link

OPTIONS - return 405 Method not allowed #96

Closed kingramizy closed 1 year ago

kingramizy commented 6 years ago

I configure nelmio for my api, (I use fosrestbundle and symfony 3.4)

my config.yml :

capture4

one of my actions :

    /**
     * @Rest\View()
     * @Rest\Get("api/v1/langue")
     */
    public function getLanguesAction(Request $request){
    $em = $this->getDoctrine()->getManager();

    $langues = $em->getRepository('PDFWSVisionLangueBundle:Langue')->findBy(array('laArchive' => '0'));
    //var_dump($langue);
    if (empty($langues)) {
        return new JsonResponse(['message' => 'not found'], Response::HTTP_NOT_FOUND);
    }

    $formatted = [];

    foreach ($langues as $langue) {
        $formatted[] = [
            'La_id' => $langue->getLaId(),
            'La_code' => $langue->getLaCode(),
            'La_libelle' => $langue->getLaLibelle(),
            'La_ordre' => $langue->getLaOrdre(),
            //'La_image' => $langue->getLaImage(),
         ];
    }
    return $formatted;
}

when I call this function: / api / v1 / language in GET I have : { "error": { "code": 405, "message": "Method Not Allowed", "exception": [ { "message": "No route found for \"OPTIONS /api/v1/langue\": Method Not Allowed (Allow: GET)", "class": "Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException",

what is wrong in my configuration?

nataliaAznar commented 6 years ago

I have the same problem. My config is:

nelmio_cors:
    defaults:
        origin_regex: true
        allow_origin: ['*']
        allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
        allow_headers: ['*']
        max_age: 3600
    paths:
        '^/': ~
rickerd commented 6 years ago

What errors do you get? Because in the end it was not Nelmio but Apache what caused my problem.

nataliaAznar commented 6 years ago

I just get a 405 without any message But I am using Nginx

leonardorifeli commented 6 years ago

I have the same problem. Any idea?

LPodolski commented 6 years ago

it's bug in bundle, explained here: https://github.com/nelmio/NelmioCorsBundle/issues/21#issuecomment-418023782