I need help. 404 Error

Hey,

I updated Slim to version 4. I had to, because I was getting a critical error.

Issue #1: In the console client I have a 504 error, and in the server console Type: Slim: SlimNotFoundException - Not Found. 404.

My index.php code looks like this:

<?php



// https://github.com/slimphp/Slim/blob/4.x/README.md

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;

$resource = new \App\AbstractResource();


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

/**
 * Instantiate App
 *
 * In order for the factory to work you need to ensure you have installed
 * a supported PSR-7 implementation of your choice e.g.: Slim PSR-7 and a supported
 * ServerRequest creator (included with Slim PSR-7)
 */
$app = AppFactory::create();

// Add Routing Middleware
$app->addRoutingMiddleware();

/**
 * Add Error Handling Middleware
 *
 * @param bool $displayErrorDetails -> Should be set to false in production
 * @param bool $logErrors -> Parameter is passed to the default ErrorHandler
 * @param bool $logErrorDetails -> Display error details in error log
 * which can be replaced by a callable of your choice.
 
 * Note: This middleware should be added last. It will not handle any exceptions/errors
 * for middleware added after it.
 */
$errorMiddleware = $app->addErrorMiddleware(true, true, true);


// Run app





$app->get('/people(/(:id)(/))', function($id = null) use ($app, $resource) {
    $result = !empty($id) ? $resource->getOneBy('App\Entity\Person', $app, array('id' => $id)) : $resource->getAll('App\Entity\Person', $app);
    echo $result;
});

$app->post('/search(/)', function() use ($app, $resource) {
    $regNo = $app->request()->post('searchString');
    echo $resource->getOneBy('App\Entity\Person', $app, array('regNo' => $regNo, 'status' => 1));
});

$app->post('/createPerson(/)', function() use ($app, $resource) {
    $person = $app->request()->post('person');
    echo $resource->replace('\App\Entity\Person', $app, $person);
});

$app->post('/updatePerson(/)', function() use ($app, $resource) {
    $person = $app->request()->post('person');
    echo $resource->replace('\App\Entity\Person', $app, $person);
});

$app->post('/deletePerson(/)', function() use ($app, $resource) {
    $id = $app->request()->post('id');
    echo $resource->delete('App\Entity\Person', $app, $id);
});

/*
$app->get('/persons(/(:id)(/))', function($id = null) use ($personResource) {
    echo $personResource->get($id);
});

$app->post('/persons', function() use ($personResource) {
    echo $personResource->post();
});

$app->put('/persons/:id', function($id = null) use ($personResource) {
    echo $personResource->put($id);
});

$app->delete('/persons/:id', function($id = null) use ($personResource) {
    echo $personResource->delete($id);
});
*/


$app->run();

Please help. I researched, used chatgpt.

Are you running this application in a subdirectory of the webserver document-root?

If yes, then try to set the basePath using $app->setBasePath('/path');