-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Match any route to OPTIONS request method #84
Comments
@akrz did you find a solution to this? |
Sort of, I do a catch of HttpMethodNotAllowedException and check that the HTTP method is OPTIONS. try {
// dispatch route...
} catch (HttpMethodNotAllowedException $e) {
if ($requestMethod === 'OPTIONS') {
$this->handleOptionsRequests($e->getMessage()); // I send an empty response with appropriate headers here
}
throw new HttpMethodNotAllowedException($e->getMessage());
} |
Apologies to the people I'm replying to here, as this thread is almost a year and a half old, I just wanted to share what I found that worked, in case someone else finds this useful. So I created a route that takes just a single parameter of 0 or more of any characters, and then just ignored that value. However, the '0' portion of that (including with the Well, yes but you have to be careful: $router->options('/{x:.*}?', function($x = null) { return httpOptions(); });
$router->options('/', function() { return httpOptions(); }); // this throws... If you add it like that, you'll get a So it even realizes that the regex route should catch it (despite it not) All is not lost though; This works just fine: $router->options('/', function() { return httpOptions(); });
$router->options('/{x:.*}?', function($x = null) { return httpOptions(); }); Handles |
Is it possible to make a route that matches all routes for a given request method? I need this to match any route to an OPTIONS request method. Something like this:
The text was updated successfully, but these errors were encountered: