• File: Cors.php
  • Full Path: /var/www/imaliapi/app/Http/Middleware/Cors.php
  • Date Modified: 11/12/2024 5:39 PM
  • File size: 955 bytes
  • MIME-type: text/x-php
  • Charset: utf-8
<?php

namespace App\Http\Middleware;

use Closure;

class Cors
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $domains = ['http://localhost:13397', 'http://localhost:8080', 'http://localhost:8081', 'http://localhost:4200/', 'https://www.paytek-africa.com'];

        if (isset($request->server()['HTTP_ORIGIN'])) {
            $origin = $request->server()['HTTP_ORIGIN'];

            if (in_array($origin, $domains)) {
                header('Access-Control-Allow-Origin: ' . $origin);
                header('Access-Control-Allow-Headers: Origin, Content-Type, Authorization');
                header('Access-Control-Allow-Methods: POST, GET, PATCH, PUT, DELETE, OPTIONS');
            }
        }

        return $next($request);
    }
}