|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * Fresns (https://fresns.org) |
| 5 | + * Copyright (C) 2021-Present Jevan Tang |
| 6 | + * Released under the Apache-2.0 License. |
| 7 | + */ |
| 8 | + |
| 9 | +namespace Plugins\ClsLogger\Providers; |
| 10 | + |
| 11 | +use Fresns\MarketManager\Models\Plugin; |
| 12 | +use Illuminate\Support\Facades\Cache; |
| 13 | +use Illuminate\Support\Facades\Route; |
| 14 | +use Illuminate\Foundation\Support\Providers\RouteServiceProvider as BaseServiceProvider; |
| 15 | + |
| 16 | +class RouteServiceProvider extends BaseServiceProvider |
| 17 | +{ |
| 18 | + /** |
| 19 | + * Called before routes are registered. |
| 20 | + * |
| 21 | + * Register any model bindings or pattern based filters. |
| 22 | + */ |
| 23 | + public function boot(): void |
| 24 | + { |
| 25 | + parent::boot(); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Define the routes for the application. |
| 30 | + */ |
| 31 | + public function map(): void |
| 32 | + { |
| 33 | + $host = null; |
| 34 | + |
| 35 | + // try { |
| 36 | + // if (class_exists(Plugin::class)) { |
| 37 | + // $fskey = 'ClsLogger'; |
| 38 | + // $cacheKey = "{$fskey}_model"; |
| 39 | + |
| 40 | + // $pluginModel = Cache::get($cacheKey); |
| 41 | + // if (empty($pluginModel)) { |
| 42 | + // $pluginModel = Plugin::withTrashed()->where('fskey', $fskey)->first(); |
| 43 | + |
| 44 | + // Cache::put($cacheKey, $pluginModel, now()->addMinutes(30)); |
| 45 | + // } |
| 46 | + |
| 47 | + // $pluginHost = $pluginModel?->plugin_host ?? ''; |
| 48 | + |
| 49 | + // $host = str_replace(['http://', 'https://'], '', rtrim($pluginHost, '/')); |
| 50 | + // } |
| 51 | + // } catch (\Throwable $e) { |
| 52 | + // info("get plugin host failed: " . $e->getMessage()); |
| 53 | + // } |
| 54 | + |
| 55 | + Route::group([ |
| 56 | + 'domain' => $host, |
| 57 | + ], function () { |
| 58 | + $this->mapApiRoutes(); |
| 59 | + |
| 60 | + $this->mapWebRoutes(); |
| 61 | + }); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Define the "web" routes for the application. |
| 66 | + * |
| 67 | + * These routes all receive session state, CSRF protection, etc. |
| 68 | + */ |
| 69 | + protected function mapWebRoutes(): void |
| 70 | + { |
| 71 | + Route::middleware('web')->group(dirname(__DIR__, 2) . '/routes/web.php'); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Define the "api" routes for the application. |
| 76 | + * |
| 77 | + * These routes are typically stateless. |
| 78 | + */ |
| 79 | + protected function mapApiRoutes(): void |
| 80 | + { |
| 81 | + Route::prefix('api')->name('api.')->middleware('api')->group(dirname(__DIR__, 2) . '/routes/api.php'); |
| 82 | + } |
| 83 | +} |
0 commit comments