Routes - '/api/ping' and '/login' always return 404 'Not Found'

1.LoginHandler is registered with ConfigProvider of App:

 public function getDependencies(): array
    {
        return [
            'invokables' => [
                Handler\PingHandler::class => Handler\PingHandler::class,
            ],
            'factories'  => [
                Handler\HomePageHandler::class => Handler\HomePageHandlerFactory::class,
                Login\LoginHandler::class => Login\LoginHandlerFactory::class,
            ],
        ];
    }

2.The login route is defined in routes.php:

return static function (Application $app, MiddlewareFactory $factory, ContainerInterface $container): void {
    $app->get('/', App\Handler\HomePageHandler::class, 'home');
    $app->get('/api/ping', App\Handler\PingHandler::class, 'api.ping');
    $app->get('/login', App\Login\LoginHandler::class, 'login');
};

3.The ConfigProvider is pulled-in in Config.php:

// Default App module config
    App\ConfigProvider::class,

But still the routes ‘/api/ping’ and ‘/login’ won’t work?

/api/ping works out of the box so it should work. What is your error/exception message?

Going to suggest that this topic was most likely solved in:

As I mentioned in the topic’s titl it gives 404 Not Found error.

Have you pushed the code to github as @froschdesign requested in your other topic? The issue has to be in the project itself due to /api/ping being a default route when building from the skeleton. If the suggestions in your other topic does not resolve the issue then we really need to be able to see all of your configuration to know what has happened to break it.

Edit to add:
When you say 404 error… How is this presented? Via the Whoops handler, is any other information provided other than 404?

Yes, the code is on Github - GitHub - sanjivsharmalv/mezzio: LoginHandler - Not Found Issue
As far as Whops is concerned, I am not sure how is error published. It is just displayed as ‘Not Found’ and and it doesn’t come from any of templates(error or 404 of layout dir).

Before we move on can you please confirm that you are in development mode?
composer development-status

The related enable command can be found in the root composer.json file in the scripts block.

Just after a quick read through it makes me ask what type of server environment you are running this app in?

To share the my environment is MAMP and the develoment status dev.

The development status should be either enabled or disabled. So, I am taking it that development mode is enabled.

My gut tells me that it’s something server related. Did you test the ping handler before trying to add any other handlers? The ping handler should absolutely work before any changes have been made. If it does not then it’s most likely a incorrectly configured vhost.

Are you running this in a subdirectory of the initial vhost in MAMP? If so that could very well be the issue. By default Mezzio expects to live in the root with the entry file (index.php) and htaccess living in the docroot which should be /public.

If it turns out that you are running in a sub directory please see this documentation:

The developmen status is ‘already enabled’.

Did you test the ping handler before trying to add any other handlers?
<<Now, since LoginHandler is already added, I removed it and then tested /api/ping, it did not work.

Are you running this in a subdirectory of the initial vhost in MAMP?
<<My vhost entry:
<VirtualHost *:8888>
ServerAdmin mezzio
DocumentRoot “/Users/sanjivsharma/mezzio/public”
ServerName mezzio.test
ServerAlias mezzio.test
ErrorLog “logs/mezzioerror_log”
CustomLog “logs/mezzioaccess_log” common

Thanks!
I assume you pulled down this repository code and tried to produce the issue at you end. if yes, please share your findings.

Not sure about your entire server setup, but you do not have AllowOverride All present so I am not sure if your htaccess file is having any effect there. You should look into how you enable it for MAMP. It’s been years since I used MAMP.

Also, if you are running a fresh install of mezzio then I really do not need to pull it since /api/ping should absolutely work as long as you have not made any changes and your dev server is correctly configured.

Included the following in

<VirtualHost *:8888>
    ServerAdmin mezzio
    DocumentRoot "/Users/sanjivsharma/multibyte/newmezzio/public"
    ServerName mezzio.loc
ServerAlias mezzio.loc
    ErrorLog "logs/mezzioerror_log"
    CustomLog "logs/mezzioaccess_log" common
<Directory "/Users/sanjivsharma/multibyte/newmezzio/public">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

I was missing the following earlier:

<Directory "/Users/sanjivsharma/multibyte/newmezzio/public">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>