0

To preface this question, I'm converting a demo application to utilize RESTful, SEO-friendly URLs; EVERY route with the exception of one of two routes used for AJAX requests works when being used in the application on the web, and ALL the routes have been completely tested using Postman - using a vanilla Nginx configuration.

That being said, here is the offending route definition(s) - the login being the defined route that's failing:

$routing_map->post('login.read', '/services/authentication/login', [
    'params' => [
        'values' => [
            'controller' => '\Infraweb\Toolkit\Services\Authentication',
            'action' => 'login',
        ]
    ]
])->accepts([
    'application/json',
]);

$routing_map->get('logout.read', '/services/authentication/logout', [
    'params' => [
        'values' => [
            'controller' => '\Infraweb\Toolkit\Services\Authentication',
            'action' => 'logout',
        ]
    ]
])->accepts([
    'application/json',
]);

With Postman & xdebug tracing I think I'm seeing that it's (obviously) failing what I believe to be a REGEX check in the Path rule, but I can't quite make it out. It's frustrating to say the least. I looked everywhere I could using web searches before posting here - the Google group for Auraphp doesn't seem to get much traffic these days. It's probable I've done something incorrectly, so I figured it was time to ask the collective user community for some direction. Any and all constructive criticism is greatly welcomed and appreciated.

Thanx in advance, and apologies for wasting anyone's bandwidth on this question...

Doktor13
  • 41
  • 1
  • 6
  • Can you post the exception you are getting. I am not in front of computer . ie why. Regarding google group, if someone asked a question there are people who tries to reply back. – Hari K T Feb 23 '19 at 07:07
  • Wild guess without knowing the version you are using etc. I believe you are using 3.x . But you are trying to make use of concepts from 2.x . The 3rd argument to $routing_map > An optional $handler (a closure, callback, action object, controller class, etc); if you do not pass a handler, the route will use the $name parameter as the handler. I recommend you reading the docs over : http://auraphp.com/packages/3.x/Router/getting-started.html#1-4-1 . Relax and read that will help you better debug this alone. Else post errors or full code to github and ping me. – Hari K T Feb 23 '19 at 07:28
  • Thanx for the quick reply @HariKT! Yeah, I was using a mixed bag of 2.x and 3.x implementation logic; examples found when searching the web turn up a mixed bag. My Bad there... I've been all over the docs at the link you've provided before I actually posted this question here, and I've already refactored things to be more aligned with V3.x. However, the error still exists so I'm pretty sure I've still have something configured or coded incorrectly. At any rate, I'll leave this here for now and continue this on github until I get it mitigated w your assistance, then close it out. – Doktor13 Feb 24 '19 at 15:39
  • Discussion continued here : [ https://github.com/auraphp/Aura.Router/issues/166 ] – Doktor13 Feb 24 '19 at 18:07

1 Answers1

0

Let me make something clear. Aura.Router doesn't do the dispatching. It only matches the route. It doesn't handle how your routes are handled.

See the full working example ( In that example the handler is assumed as callable )

$callable = $route->handler;
$response = $callable($request);

In your case if you matched the request ( See matching request )

$matcher = $routerContainer->getMatcher();
$route = $matcher->match($request);

you will get the route, now you need to write appropriate ways how to handle the values from the $route->handler.

This is what I did after var_dump the $route->handler for the /signin route .

array (size=1)
'params' => 
    array (size=1)
    'values' => 
        array (size=2)
        'controller' => string '\Infraweb\LoginUI' (length=17)
        'action' => string 'read' (length=4)

Full code tried below. As I mentioned before I don't know your route handling logic. So it is up to you to write things properly.

<?php
require __DIR__ . '/vendor/autoload.php';

use Aura\Router\RouterContainer;

$routerContainer = new RouterContainer();

$map = $routerContainer->getMap();

$request = Zend\Diactoros\ServerRequestFactory::fromGlobals(
    $_SERVER,
    $_GET,
    $_POST,
    $_COOKIE,
    $_FILES
);

$map->get('application.signin.read', '/signin', [
    'params' => [
        'values' => [
            'controller' => '\Infraweb\LoginUI',
            'action' => 'read',
        ]
    ]
]);

$map->post('login.read', '/services/authentication/login', [
    'params' => [
        'values' => [
            'controller' => '\Infraweb\Toolkit\Services\Authentication',
            'action' => 'login',
        ]
    ]
])->accepts([
    'application/json',
]);


$matcher = $routerContainer->getMatcher();

// .. and try to match the request to a route.
$route = $matcher->match($request);
if (! $route) {
    echo "No route found for the request.";
    exit;
}

echo '<pre>';
var_dump($route->handler);
exit;

For the record, this is the composer.json

{ "require": { "aura/router": "^3.1", "zendframework/zend-diactoros": "^2.1" } }

and running via

php -S localhost:8000 index.php

and browsing http://localhost:8000/signin

Hari K T
  • 4,174
  • 3
  • 32
  • 51
  • Let me be a bit clearer regarding this issue; the route in your example isn't the one in question. ANY route that's UI related doesn't have issue at all, the route in question is the '_/services/authentication/login_' route path (_js fetch api call_), that _somehow_ is failing the Path rule '_/signin_' (_standard request_). FWIW, everything else is practically the same as above. I've also refactored from using a dispatcher I wrote to the diactoros response class package - which didn't change things but leaves an msg in the php-fpm error log. I'll tackle that later once this is solved - thx! – Doktor13 Feb 25 '19 at 17:19
  • @Doktor13 I did changed the route as in your example and there is no issues with post request via postman. I don't think the router is the problem, if you are sure, as I said before keep the full code in your github repo, so we only need to do composer install to test it. – Hari K T Feb 27 '19 at 06:20