jdesrosiers / silex-cors-provider

A silex service provider that adds CORS services to silex
MIT License
78 stars 25 forks source link

OPTION method not injected when using optional parameter in route #28

Closed vitxd closed 8 years ago

vitxd commented 8 years ago

Hello, first of all thank you very much for this!

I'm not sure is a problem with your class or what, so apologies if it is not. I started experiencing this problem when I moved routes from a single file to controller providers so the problem might be there.

I have a route that matches /customer and I then mount to it other sub routes. The first defined is

  path: '{id}'
  defaults: { _controller: 'customer.controller:getAction', id: 0 }
  requirements:
    id: \d+
  methods: [GET]

so that should match both /customer and /customer/3.

If I try to access the route /customer directly it is resolved, if I try to access it with a browser and a using CORS, it will detect the route but it will fail saying OPTION is not a method allowed. I have the feeling that the OPTION method has been injected in the /customer/ route instead of the /customer but I have no way to prove it :D

Do you have idea why this is happening? I hope to have been clear enough!

===UPDATE=== I managed to recreate the same and also managed to prove that OPTIONS method is attached to the route with the trailing slash not to the one without while the silex router resolve the latter.

jdesrosiers commented 8 years ago

I think you are running into a known limitation of mount.

When mounting a route collection under /blog, it is not possible to define a route for the /blog URL. The shortest possible URL is /blog/.

My guess is that the OPTIONS method has a trailing / because original customer route has a trailing / that you might not realize is there.