php think make:middleware Cross
* 設(shè)置跨域
* @param $request
* @param \Closure $next
* @return mixed|void
*/
public function handle($request, \Closure $next)
{
header('Access-Control-Allow-Origin: *');
header('Access-Control-Max-Age: 1800');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE');
header('Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With, Token');
if (strtoupper($request->method()) == "OPTIONS") {
return Response::create()->send();
}
return $next($request);
}
<?php
// 全局中間件定義文件
return [
// 全局請(qǐng)求緩存
// \think\middleware\CheckRequestCache::class,
// 多語(yǔ)言加載
// \think\middleware\LoadLangPack::class,
// Session初始化
// \think\middleware\SessionInit::class
//解決跨域問(wèn)題 自定義Cross中間件
\app\middleware\Cross::class
];
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)