소스 검색

更新报错信息的显示;修复 websocket 请求头的问题

zjcqoo 6 년 전
부모
커밋
76af4452c3
1개의 변경된 파일30개의 추가작업 그리고 10개의 파일을 삭제
  1. 30 10
      api.conf

+ 30 - 10
api.conf

@@ -1,12 +1,3 @@
-if ($_origin_id = '') {
-  return              403   'ERROR: origin `$http_origin` is not allowed';
-}
-if ($http_x_jsproxy) {
-  return              500   'ERROR: circular dependency';
-}
-proxy_set_header      x-jsproxy   1;
-proxy_set_header      Connection  $http_connection;
-
 set                   $_level     '';
 set                   $_switched  '';
 set                   $_url       '';
@@ -16,6 +7,20 @@ set                   $_type      '';
 set                   $_mode      '';
 set                   $_bodyhash  '';
 
+error_page            500 502 504 /error;
+
+location = /error {
+  internal;
+  access_log          off;
+  more_set_headers
+    'access-control-allow-origin: *'
+    'access-control-expose-headers: gateway-err--'
+    'gateway-err--: {"msg": "$arg_msg", "addr": "$upstream_addr"}'
+  ;
+  return              204;
+}
+
+
 location = /preflight {
   internal;
   access_log          off;
@@ -31,8 +36,19 @@ location = /preflight {
 
 # HTTP(S) Proxy
 location = /http {
+  # see ./allowed-sites.conf
+  if ($_origin_id = '') {
+    rewrite             ^   /error?msg=ORIGIN_NOT_ALLOWED;
+  }
+  if ($http_x_jsproxy) {
+    rewrite             ^   /error?msg=CIRCULAR_DEPENDENCY;
+  }
+  proxy_set_header      x-jsproxy   1;
+  proxy_set_header      Connection  $http_connection;
+  
+
   if ($http_access_control_request_headers) {
-    rewrite           ^   /preflight;
+    rewrite             ^   /preflight;
   }
 
   access_by_lua_file    ../lua/http-dec-req-hdr.lua;
@@ -45,6 +61,8 @@ location = /http {
     'content-security-policy'
     'content-security-policy-report-only'
     'x-frame-options'
+    'alt-svc'
+    'clear-site-data'
   ;
   header_filter_by_lua_file   ../lua/http-enc-res-hdr.lua;
   body_filter_by_lua_file     ../lua/http-body-hash.lua;
@@ -54,5 +72,7 @@ location = /http {
 # WebSocket Proxy
 location = /ws {
   access_by_lua_file    ../lua/ws-dec-req-hdr.lua;
+  proxy_set_header      Upgrade     $http_upgrade;
+  proxy_set_header      Connection  $http_connection;
   proxy_pass            $_url;
 }