Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
🎨 organized example routes into modules
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Apr 30, 2021
1 parent c887f45 commit dd57c4e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
12 changes: 12 additions & 0 deletions App/Routes/_app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

/**@var Leaf\App $app */

$app->get("/", function () {
json(["message" => "Congrats!! You're on Leaf API"], 200);
});

$app->get("/app", function () {
// app() returns $app
json(app()->routes(), 200);
});
45 changes: 23 additions & 22 deletions App/Routes/index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

/**@var Leaf\App $app */

/*
|--------------------------------------------------------------------------
| Set up 404 handler
Expand All @@ -12,6 +14,24 @@
json("Resource not found", 404, true);
});

/*
|--------------------------------------------------------------------------
| Set up 500 handler
|--------------------------------------------------------------------------
|
| Create a handler for error 500
|
*/
$app->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
Expand All @@ -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";
// You can break up routes into individual files
require __DIR__ . "/_app.php";
require __DIR__ . "/_auth.php";

0 comments on commit dd57c4e

Please sign in to comment.