api.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. use Illuminate\Http\Request;
  3. /*
  4. |--------------------------------------------------------------------------
  5. | API Routes
  6. |--------------------------------------------------------------------------
  7. |
  8. | Here is where you can register API routes for your application. These
  9. | routes are loaded by the RouteServiceProvider within a group which
  10. | is assigned the "api" middleware group. Enjoy building your API!
  11. |
  12. */
  13. Route::prefix('v1')
  14. ->group(function () {
  15. // Admin
  16. Route::prefix('admin')
  17. ->middleware('admin')
  18. ->group(function () {
  19. Route::any('/{class}/{action}', function($class, $action) {
  20. $ctrl = \App::make("\\App\\Http\\Controllers\\Admin\\" . ucfirst($class) . "Controller");
  21. try {
  22. return \App::call([$ctrl, $action]);
  23. } catch (\Exception $e) {
  24. abort(404, 'not found');
  25. }
  26. });
  27. });
  28. // User
  29. Route::prefix('user')
  30. ->middleware('user')
  31. ->group(function () {
  32. Route::any('/{action}', function($action) {
  33. $ctrl = \App::make("\\App\\Http\\Controllers\\User\\UserController");
  34. try {
  35. return \App::call([$ctrl, $action]);
  36. } catch (\Exception $e) {
  37. abort(404, 'not found');
  38. }
  39. });
  40. Route::any('/{class}/{action}', function($class, $action) {
  41. $ctrl = \App::make("\\App\\Http\\Controllers\\User\\" . ucfirst($class) . "Controller");
  42. try {
  43. return \App::call([$ctrl, $action]);
  44. } catch (\Exception $e) {
  45. abort(404, 'not found');
  46. }
  47. });
  48. Route::get('server/log/fetch', 'User\\ServerController@logFetch');
  49. });
  50. // Passport
  51. Route::prefix('passport')
  52. ->group(function () {
  53. Route::any('/{class}/{action}', function($class, $action) {
  54. $ctrl = \App::make("\\App\\Http\\Controllers\\Passport\\" . ucfirst($class) . "Controller");
  55. try {
  56. return \App::call([$ctrl, $action]);
  57. } catch (\Exception $e) {
  58. abort(404, 'not found');
  59. }
  60. });
  61. });
  62. // No Auth
  63. Route::prefix('guest')
  64. ->group(function () {
  65. Route::any('/{class}/{action}', function($class, $action) {
  66. $ctrl = \App::make("\\App\\Http\\Controllers\\Guest\\" . ucfirst($class) . "Controller");
  67. try {
  68. return \App::call([$ctrl, $action]);
  69. } catch (\Exception $e) {
  70. abort(404, 'not found');
  71. }
  72. });
  73. });
  74. // Client
  75. Route::prefix('client')
  76. ->middleware('client')
  77. ->group(function () {
  78. Route::any('/{action}', function($action) {
  79. $ctrl = \App::make("\\App\\Http\\Controllers\\Client\\ClientController");
  80. try {
  81. return \App::call([$ctrl, $action]);
  82. } catch (\Exception $e) {
  83. abort(404, 'not found');
  84. }
  85. });
  86. Route::any('/{class}/{action}', function($class, $action) {
  87. $ctrl = \App::make("\\App\\Http\\Controllers\\Client\\" . ucfirst($class) . "Controller");
  88. try {
  89. return \App::call([$ctrl, $action]);
  90. } catch (\Exception $e) {
  91. abort(404, 'not found');
  92. }
  93. });
  94. });
  95. // Server
  96. Route::prefix('server')
  97. ->group(function () {
  98. Route::any('/{class}/{action}', function($class, $action) {
  99. $ctrl = \App::make("\\App\\Http\\Controllers\\Server\\" . ucfirst($class) . "Controller");
  100. try {
  101. return \App::call([$ctrl, $action]);
  102. } catch (\Exception $e) {
  103. abort(404, 'not found');
  104. }
  105. });
  106. });
  107. });