From dd57c4ec109c3aaef797278dec3995fb23182c32 Mon Sep 17 00:00:00 2001 From: mychi darko Date: Fri, 30 Apr 2021 19:51:06 +0000 Subject: [PATCH] :art: organized example routes into modules --- App/Routes/_app.php | 12 ++++++++++++ App/Routes/index.php | 45 ++++++++++++++++++++++---------------------- 2 files changed, 35 insertions(+), 22 deletions(-) create mode 100644 App/Routes/_app.php diff --git a/App/Routes/_app.php b/App/Routes/_app.php new file mode 100644 index 0000000..1bb9c15 --- /dev/null +++ b/App/Routes/_app.php @@ -0,0 +1,12 @@ +get("/", function () { + json(["message" => "Congrats!! You're on Leaf API"], 200); +}); + +$app->get("/app", function () { + // app() returns $app + json(app()->routes(), 200); +}); diff --git a/App/Routes/index.php b/App/Routes/index.php index 46673ba..259ec14 100644 --- a/App/Routes/index.php +++ b/App/Routes/index.php @@ -1,5 +1,7 @@ setErrorHandler(function ($e = null) use($app) { + if ($e) { + if ($app->config("log.enabled")) { + $app->logger()->error($e); + } + } + + json("An error occured, our team has been notified", 500, true); +}); + /* |-------------------------------------------------------------------------- | Set up Controller namespace @@ -23,25 +43,6 @@ */ $app->setNamespace("\App\Controllers"); - -// $app is the instance of Leaf -$app->get("/", function () { - json(["message" => "Congrats!! You're on Leaf API"], 200); -}); - -$app->get("/app", function () { - // app() returns $app - json(app()->routes(), 200); -}); - -// From v1.1, you can use this Route method anywhere in your app -// This links to the login method of the UsersController -// Route("POST", "/login", "UsersController@login"); - -// You can define your routes here directly or -// import an independent route file - -// Example authentication has been created for you to give you -// an idea on working with this version of leaf. To get rid of all -// the comments, simply run php leaf scaffold:auth --api -require __DIR__ . "/_auth.php"; \ No newline at end of file +// You can break up routes into individual files +require __DIR__ . "/_app.php"; +require __DIR__ . "/_auth.php";