123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- // +----------------------------------------------------------------------
- // | [ WE CAN DO IT MORE SIMPLE ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2018-2020 rights reserved.
- // +----------------------------------------------------------------------
- // | Author: TABLE ME
- // +----------------------------------------------------------------------
- // | Date: 2020-08-30 14:59
- // +----------------------------------------------------------------------
- namespace app\admin\middleware;
- use app\Request;
- use library\interfaces\MiddlewareInterface;
- use \think\facade\Config;
- use think\Response;
- class AllowOriginMiddleware implements MiddlewareInterface {
- public function handle(Request $request, \Closure $next)
- {
- $origin = $request->header('origin');
- $header['Access-Control-Allow-Origin'] = '*';
- $header['Access-Control-Allow-Methods'] = 'POST,GET,JSON,OPTIONS,DELETE';
- $header['Access-Control-Allow-Headers'] = 'x-requested-with,content-type,WAREHOUSE-TOKEN,SECRET-KEY,SYSTEM-ACC-TOKEN,TOKEN,'. Config::get('cookie.admin_token_name','');
- if ($request->method(true) == 'OPTIONS') {
- $response = Response::create('ok')->code(200)->header($header);
- } else {
- $response = $next($request)->header($header);
- }
- return $response;
- }
- }
|