Built-in server and route params (file extensions), how do you handle it?



Using the built-in webserver on travis and realized that it won’t call ‘public/index.php’ when the route contains a file extension… Imagine the following route (fastroute, expressive 3):

return function (Application $app, MiddlewareFactory $factory, ContainerInterface $container) : void {
    //$app->get('/', App\Handler\HomePageHandler::class, 'home');

    $app->get('/api/order/{order_id:\d+}.{format:json|xml}', new class() implements RequestHandlerInterface {
        public function handle(ServerRequestInterface $request): ResponseInterface
            return (new JsonResponse([
		'format' => $request->getAttribute('format'),
                'order_id' => $request->getAttribute('order_id') 	
    }, 'order-route');    

Start the built-in server (composer serve or php -S 0.0.0:1234 -t public/) and try to reach http://localhost/api/order/12.json as an example… You’ll probably have a 404 (tested with PHP7.1, 7.2 latests)… the built-in webserver does not even call the public/index.php


$ php -S -t public/ $(pwd)/public/index.php

will do the trick, but was curious if someone had found a better way to do it ?


Use docker containers?

Or don’t start a webserver, but test the application by feeding it a constructed route.


@xtreamwayz thanks… I think you’re right. (edited: was using it for smoke tests, that’s why)