Replies: 7 comments 2 replies
-
So I see why it does it. In the core code, it stores things by the url and then the method. Technically how you coded that ends up with this result. // internal storage of routes
$routes = [
0 => [
'url' => '/login'
'methods' => 'POST'
],
1 => [
'url' => '/login'
'methods' => 'GET'
],
]; So what happens is it goes through each array key to find the url. Since it matches the first one, then it checks the methods and since GET isn't there that's why.... I'll think through on how to adjust it moving forward. And no, there is no method like a |
Beta Was this translation helpful? Give feedback.
-
Actually now that I'm able to test it locally, it actually is working for me. I'm not getting any errors. This is my code on the latest version of Flight....maybe you need to update? <?php
declare(strict_types=1);
require 'flight/autoload.php';
Flight::route('POST /login', function () {
echo 'hello world from POST!';
});
Flight::route('GET /login', function () {
echo 'hello world from GET!';
});
Flight::start(); |
Beta Was this translation helpful? Give feedback.
-
I just did a
But unfortunately the problem persists. I'm not sure why it works for you though, if you haven't changed the way the array is scanned 🤔 And, when you scan the array, should you really only match the URL if methods is not empty? I would consider an empty methods field to mean "all", and a non matching methods to make it skip to the next entry. Setting an indicator that you did find at least one URL match would let you throw the methodNotAllowed() after you've scanned all endpoints/URLs. With, for example, and API, it's quite common to have different code handle different methods, even if it's the same endpoint. |
Beta Was this translation helpful? Give feedback.
-
Well, my "bootstrap" looks a bit different, hence my code. It looks something like this:
So I'm not adding the endpoints exactly like you are. But I don't quite see why/how that would make a difference 🤔 |
Beta Was this translation helpful? Give feedback.
-
Walking through the routes like this:
Yields this:
So it's registering them correctly, but apparently something fails while parsing them 🤔 But if the parser considers that an URL match is finite, and not URL + METHOD, then I guess it's obvious where/why/how the "issue" occurs. |
Beta Was this translation helpful? Give feedback.
-
In
|
Beta Was this translation helpful? Give feedback.
-
After going backwards, and also reading the above code, I think I found a typo (on my side). Mea culpa as they say 🫤 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Two questions really:
Are there more specific error handlers than
notFound
, e.g. one formethodNotAllowed
? 🤔Why am I getting a Method Not Allowed error when I POST here, but not when I GET? 🤔
Beta Was this translation helpful? Give feedback.
All reactions