Procházet zdrojové kódy

pre方法兼容跨域

Yahoo před 4 roky
rodič
revize
dd4eac46c0
3 změnil soubory, kde provedl 6 přidání a 3 odebrání
  1. 1 2
      app/common.php
  2. 1 1
      config/trace.php
  3. 4 0
      cores/ExceptionHandle.php

+ 1 - 2
app/common.php

@@ -31,10 +31,9 @@ use think\exception\HttpResponseException;
  */
 function pre($content, bool $export = false)
 {
-    header('Content-type: text/html; charset=utf-8');
     $output = $export ? var_export($content, true) : print_r($content, true);
     echo "<pre>{$output}</pre>";
-    die;
+    app_end();
 }
 
 /**

+ 1 - 1
config/trace.php

@@ -4,7 +4,7 @@
 // +----------------------------------------------------------------------
 return [
     // 内置Html和Console两种方式 支持扩展
-    'type'    => 'Html',
+    'type'    => 'Console',
     // 读取的日志通道名
     'channel' => '',
 ];

+ 4 - 0
cores/ExceptionHandle.php

@@ -17,6 +17,7 @@ use think\facade\Log;
 use think\facade\Request;
 use think\exception\Handle;
 use think\db\exception\PDOException;
+use think\exception\HttpResponseException;
 use cores\exception\BaseException;
 
 /**
@@ -55,6 +56,9 @@ class ExceptionHandle extends Handle
      */
     public function render($request, Throwable $e): Response
     {
+        if ($e instanceof HttpResponseException) {
+            return $e->getResponse();
+        }
         // 手动触发的异常 BaseException
         if ($e instanceof BaseException) {
             $this->status = $e->status;