<?php

namespace App\Http\Middleware;

use Closure;

class Cors
{
    public function handle($request, Closure $next)
    {
        $domains = ['http://192.168.1.222:8080'];
        $origin = $request->server()['HTTP_ORIGIN'] ?? false;
        if ($origin && in_array($origin, $domains)) {
            header('Access-control-Allow-Origin: ' . $origin);
            header('Access-control-Allow-Headers: Origin, Content-Type, Authorization');
            header('Access-control-Allow-Methods: *');
        } 
        return $next($request);
    }
}

 

posted on 2017-03-11 16:18  jzfan  阅读(211)  评论(0编辑  收藏  举报