12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- namespace App\Http\Middleware;
- use Closure;
- class CorsMiddleware
- {
- protected $urls = ['/admin/view/attach-download/*', '/admin/user/student-export', '/admin/tcm/patient-export', '/api/course/attach-download/*'];
- /**
- * Handle an incoming request.
- *
- * @param \Illuminate\Http\Request $request
- * @param \Closure $next
- * @return mixed
- */
- public function handle($request, Closure $next)
- {
- $response = $next($request);
- $paths = $this->urls;
- foreach ($paths as $path) {
- if ($path !== '/') {
- $path = trim($path, '/');
- }
- if ($request->fullUrlIs($path) || $request->is($path)) {
- return $response;
- }
- }
- $response->header('Access-Control-Allow-Origin', '*');
- $response->header('Access-Control-Allow-Methods', '*');
- $response->header('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With');
- return $response;
- }
- }
|