|
2 | 2 |
|
3 | 3 | namespace DreamFactory\Core\Providers; |
4 | 4 |
|
5 | | -use Fruitcake\Cors\HandleCors; |
6 | | -use Fruitcake\Cors\CorsService; |
| 5 | +use DreamFactory\Core\Services\DfCorsService; |
7 | 6 | use DreamFactory\Core\Models\CorsConfig; |
| 7 | +use Fruitcake\Cors\CorsService; |
| 8 | +use Illuminate\Http\Middleware\HandleCors; |
8 | 9 | use Illuminate\Database\QueryException; |
9 | 10 | use Illuminate\Contracts\Http\Kernel; |
10 | 11 | use Illuminate\Http\Request; |
@@ -35,21 +36,15 @@ public function register() |
35 | 36 | */ |
36 | 37 | public function boot(Request $request, Kernel $kernel) |
37 | 38 | { |
| 39 | + $api_prefix = config('df.api_route_prefix', 'api'); |
| 40 | + config(['cors.paths' => [$api_prefix . '/*']]); |
| 41 | + |
38 | 42 | $config = $this->getOptions($request); |
39 | 43 | $this->app->singleton(CorsService::class, function () use ($config){ |
40 | | - return new CorsService($config); |
| 44 | + return new DfCorsService($config); |
41 | 45 | }); |
42 | 46 |
|
43 | | - /** @noinspection PhpUndefinedMethodInspection */ |
44 | | - //$this->app['router']->middleware('cors', HandleCors::class); |
45 | | - |
46 | | - if (method_exists(\Illuminate\Routing\Router::class, 'aliasMiddleware')) { |
47 | | - Route::aliasMiddleware('df.cors', HandleCors::class); |
48 | | - } else { |
49 | | - /** @noinspection PhpUndefinedMethodInspection */ |
50 | | - Route::middleware('df.cors', HandleCors::class); |
51 | | - } |
52 | | - |
| 47 | + Route::aliasMiddleware('df.cors', HandleCors::class); |
53 | 48 | Route::prependMiddlewareToGroup('df.api', 'df.cors'); |
54 | 49 | } |
55 | 50 |
|
|
0 commit comments