12345678910111213141516171819202122232425262728293031 |
- <?php
- namespace App\Http\Middleware;
- use Closure;
- use Illuminate\Http\Request;
- class AllMiddleware
- {
- public function handle(Request $request, Closure $next)
- {
- //允许跨域调用
- $allowed_origins = [
- 'http://localhost:9527',
- 'http://localhost:8080',
- 'http://192.168.1.54:9527',
- ];
-
- if (isset($_SERVER['HTTP_ORIGIN']) && in_array($_SERVER['HTTP_ORIGIN'], $allowed_origins)) {
- header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
- }
- // header('Access-Control-Allow-Origin: *');
- header("Access-Control-Allow-Headers: Authorization, Sec-Fetch-Mode, DNT, X-Mx-ReqToken, Keep-Alive, User-Agent, If-Match, If-None-Match, If-Unmodified-Since, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Accept-Language, Origin, Accept-Encoding,Access-Token,token,platform");
- header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE');
- header('Access-Control-Max-Age: 1728000');
- header('Access-Control-Allow-Credentials:true');
- return $next($request);
- }
- }
|