Slim Skeleton shows 500 error right after setup

Right after composer create-project slim/slim-skeleton myslimsite, I ran composer start and went to localhost:8080/users/ which returned a json object as below.

{
    "statusCode": 404,
    "error": {
        "type": "RESOURCE_NOT_FOUND",
        "description": "Not found."
    }
}{
    "statusCode": 500,
    "error": {
        "type": "SERVER_ERROR",
        "description": "ERROR: ob_clean(): failed to delete buffer. No buffer to delete on line 28 in file \/Volumes\/WD Mac\/work\/test\/slim-project\/myslimsite\/src\/Application\/ResponseEmitter\/ResponseEmitter.php."
    }
}

Any help on this much appreciated.

Update:

I just changed the line 28 of ResponseEmitter.php to if(ob_get_contents()) ob_clean(); which took off the 500 Server Error, but still have problem with route /users/ (Trailing Slash) but no 404 with route /users.

I installed Trailing Slash middleware as mentioned in the documentation by

composer require middlewares/trailing-slash

and adding this line to /app/middleware.php

<?php
declare(strict_types=1);

use App\Application\Middleware\SessionMiddleware;
use Middlewares\TrailingSlash;
use Slim\App;

return function (App $app) {
    $app->add(new TrailingSlash(true));
    $app->add(SessionMiddleware::class);
};

Still no luck with trailing slashes, shows 404 for routes with /.

Hello @gopumon,

According to docs: Trailing / in route patterns - Slim Framework

Slim treats a URL pattern with a trailing slash as different to one without. That is, /user and /user/ are different and so can have different callbacks attached.

What’s your intention, to use with or without trailing slashes?

If you change
new TrailingSlash(true) to
new TrailingSlash(false)
you will remove trailing slashes from the routes.

Hi @farukgaric, Thank you for your reply.

I used $app->add(new TrailingSlash(false)); to, but not modifying the uri.

I can see that the middleware is initiating only when I go to /users not on /users/.

My intention is to render the page for both, one with trailing slash and the one without it.
http://localhost:8080/users and http://localhost:8080/users/ should return the list of all users.

Update:

@l0gicgate just updated the Slim-Skeleton to 4.0.1 which took away the error 500.

Now the issue is with TrailingSlashes.
As mentioned in the User Guide > Cook Books > Trailing / in routes

I added it in /app/middleware.php

<?php
declare(strict_types=1);

use App\Application\Middleware\SessionMiddleware;
use Middlewares\TrailingSlash;
use Slim\App;

return function (App $app) {
    $app->add(new TrailingSlash(false));
    $app->add(SessionMiddleware::class);
};

Still routes with trailing / are not getting redirected to routes without /. It just shows 404. Is my middleware implementation wrong?