I have a group of routes, prefixed by /api, that returns JSON results when the user requests something from them.
That means, when a user asks for a non-existing route under /api, I want to return a JSON with a custom error (basically the not found message wrapped in a JSON object). The regular not found page, used for static files for example, still exists.
I want to do something like this:
$app->group(‘/api’, function (Group $group) use ($app) {
$group->get(‘/{resource}/{id:[0-9]+/’, JsonHandler::class . ‘:get’);
//other routes…
//…
$group->any(‘/.*’, JsonHandler::class . ‘notFound’);
});
This throws a error from RegexBasedAbstract , "Static route \"\/api\/.*\" is shadowed by previously defined variable route \"\/api\/([^\/]+)\" for method \"GET\""
, which is completely expected, since the first route does shadows the last.
How do I achieve this? I guess I could do it by writing a regex that negates all other regexes but uh, that doesnt seem like a great idea.