11<?php
22
3+ /**@var Leaf\App $app */
4+
35/*
46|--------------------------------------------------------------------------
57| Set up 404 handler
1214 json ("Resource not found " , 404 , true );
1315});
1416
17+ /*
18+ |--------------------------------------------------------------------------
19+ | Set up 500 handler
20+ |--------------------------------------------------------------------------
21+ |
22+ | Create a handler for error 500
23+ |
24+ */
25+ $ app ->setErrorHandler (function ($ e = null ) use ($ app ) {
26+ if ($ e ) {
27+ if ($ app ->config ("log.enabled " )) {
28+ $ app ->logger ()->error ($ e );
29+ }
30+ }
31+
32+ json ("An error occured, our team has been notified " , 500 , true );
33+ });
34+
1535/*
1636|--------------------------------------------------------------------------
1737| Set up Controller namespace
2343*/
2444$ app ->setNamespace ("\App\Controllers " );
2545
26-
27- // $app is the instance of Leaf
28- $ app ->get ("/ " , function () {
29- json (["message " => "Congrats!! You're on Leaf API " ], 200 );
30- });
31-
32- $ app ->get ("/app " , function () {
33- // app() returns $app
34- json (app ()->routes (), 200 );
35- });
36-
37- // From v1.1, you can use this Route method anywhere in your app
38- // This links to the login method of the UsersController
39- // Route("POST", "/login", "UsersController@login");
40-
41- // You can define your routes here directly or
42- // import an independent route file
43-
44- // Example authentication has been created for you to give you
45- // an idea on working with this version of leaf. To get rid of all
46- // the comments, simply run php leaf scaffold:auth --api
47- require __DIR__ . "/_auth.php " ;
46+ // You can break up routes into individual files
47+ require __DIR__ . "/_app.php " ;
48+ require __DIR__ . "/_auth.php " ;
0 commit comments