-
Notifications
You must be signed in to change notification settings - Fork 139
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
Slim 3 passthrough all routes when installed in subfolder #9
Comments
Just tested with Apache 2.2.15 on fresh CentOS 6.5 install. Everything works as expected. $app = new \Slim\App;
$app->add(new \Slim\Middleware\JwtAuthentication([
"secure" => false,
"secret" => "supersecretkeyyoushouldnotcommittogithub",
"rules" => [
new \Slim\Middleware\JwtAuthentication\RequestPathRule([
"path" => "/",
"passthrough" => ["/api/ping"]
]),
new \Slim\Middleware\JwtAuthentication\RequestMethodRule([
"passthrough" => ["OPTIONS"]
])
]
]));
$app->get("/", function ($request, $response, $args) {
return $response->write("hello");
});
$app->get("/foo", function ($request, $response, $args) {
return $response->write("foo");
});
$app->get("/bar", function ($request, $response, $args) {
return $response->write("bar");
});
$app->get("/api/ping", function ($request, $response, $args) {
return $response->write("ping");
});
$app->run(); Yields
|
As a sidenote you should move |
I forgot to mention, maybe it's important, the route is in a group and calling external controllers, something like this: $app->group("/api", function () { My index.php app is in a subfolder structure www/api/v3/public |
Test the code above to see if it works with your Apache. If not then it is probably server config issue. If yes then can you provide minimal code which I can reproduce the bug with. |
Don't work. I do a fresh install and it just passthrough with your code above. Foo route returning status 200 at http://192.168.0.33/api/v4/public/foo it's running over windows xamp. As I said previously, I'm not running directly on server root, as you do in https://192.168.50.10/foo, but on slim 2 it's not a problem |
I tried php built-in server to call http://192.168.0.33:1337/foo still get 200 code. My .htaccess:
My index.php code test:
Composer requires:
I do a fresh install and just requires Slim 3 and Slim-jwt-auth 2dev |
There is 200 code but what is the actual response? Response should be require __DIR__ . "/vendor/autoload.php"; PHP builtin server does not use .htaccess file so it kind of moot. |
Response is foo, it's passing. Vendor autoload file is ok, it's serving and all routes still unprotected. |
Copy pasted your composer.json and index.php. Fixed the vendor require as mentioned above. Works as expected.
|
Unrarred your file, ran composer install and internal PHP webserver. Works as expected. Feels like Windows issue to me. Could also try clearing the composer cache just in case.
|
Installed the lastest version of XAMP on windows, tried and same issue occurs, maybe it's a windows issue, because I have installed a totally fresh new webserver with php 5.6.12 |
I would check Vagrant. Having same development and deployment environment is a real life saver. Less "Works on my machine" issues :) |
WAMP also fails, maybe a native windows problem. Slim 2 works fine on both XAMP/WAMP. Could you compress a project and pass the link? I wanna try uncompress here and install with composer for tests. |
I found a clue. If RequestPathRule is defined, it fails, if there's no RequestPathRule defined in rules, middleware works fine, but, in my case, I can't define public routes. It works:
It doesn't work:
I've tested in alot of routes, namespaces and groups possible, it's not miss configuration because the same code works on slim 2, it's just RequestPathRule problem, when missed, middleware works. |
It is most likely this line which returns different value in Windows and *NIX hosts when using Slim 3. I do not use Windows myself so cannot debug. |
I debug their two tuupola/slim-jwt-auth version 1.x 2.x and found the following error. file slim-jwt-auth/src/JwtAuthentication/RequestPathRule.php in version 2.x in version 1.x with this regular expression under the function will not work correctly. Sorry my English because I am Brazilian |
I'm brazilian too =) For some reason, in slim 2 this package works really fine, but, in slim 3, doesn't =( |
$uri = $request->getUri()->getPath(); while they do not release the patch. |
@tuupola as @elvispdosreis mentioned, at line 34 $uri = $request->getUri()->getPath(); changes to $uri = "/".$request->getUri()->getPath(); works o/ |
Is this in Windows version only or also *NIX? Note that Slim 3 itself is not released yet. There is only release candidate so breaks might occur. |
Windows PHP 5.6.11 NTS |
I cannot reproduce with OSX nor Linux so it seems like Windows issue. Because I do not have access to Windows can you test what the following returns. <?php
require_once "./vendor/autoload.php";
$app = new \Slim\App;
$app->get("/foo/bar", function ($request, $response, $args) {
return $response->write($request->getUri()->getPath() . "\n");
});
$app->run(); For me it returns the following.
Apparently in Windows you get only foo/bar? |
this in windows I get foo/bar only if the initial route bar |
Windows 8. @elvispdosreis patch fix the problem. |
Thanks. Did some more testing and it happens also in *NIX hosts when installed into subfolder. My mistake, I did not test this in subfolder myself. Not sure yet if it is a bug or feature. |
Submitted a bug report slimphp/Slim#1554. |
Thanks |
This should now be fixed in 2.0.1. |
Great. Keep your good job. |
When no public routes set, middleware runs ok, but when add the following:
Middleware just don't check JWT and passthrough all routes. The same code works fine on Slim 2, but Slim 3 don't.
Ps: Works fine on php built-in server, (without any dot (.) char in uri params), Apache doesn't work, passthrough all routes. Current .htaccess:
The text was updated successfully, but these errors were encountered: