AllMiddleware.php 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\Http\Middleware;
  3. use Closure;
  4. use Illuminate\Http\Request;
  5. class AllMiddleware
  6. {
  7. public function handle(Request $request, Closure $next)
  8. {
  9. //允许跨域调用
  10. $allowed_origins = [
  11. 'http://localhost:9527',
  12. 'http://localhost:8080',
  13. 'http://192.168.1.54:9527',
  14. ];
  15. if (isset($_SERVER['HTTP_ORIGIN']) && in_array($_SERVER['HTTP_ORIGIN'], $allowed_origins)) {
  16. header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
  17. }
  18. // header('Access-Control-Allow-Origin: *');
  19. 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");
  20. header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE');
  21. header('Access-Control-Max-Age: 1728000');
  22. header('Access-Control-Allow-Credentials:true');
  23. return $next($request);
  24. }
  25. }