Browse Source

bugfix: 修改gzip开关相反的问题,修复access_log校验问题

tuon 1 year ago
parent
commit
34d039102b

+ 8 - 1
src/config/nginx_form.json

@@ -430,7 +430,8 @@
           "key": "http.access_log",
           "title": "访问日志",
           "type": "access_log",
-          "required": false
+          "required": false,
+          "stream": false
         },
         {
           "key": "http.error_log",
@@ -642,6 +643,12 @@
       "title": "端口",
       "width": 100
     },
+    {
+      "key": "isUdp",
+      "type": "switch",
+      "value": false,
+      "title": "是否UDP"
+    },
     {
       "key": "proxy_pass",
       "type": "stream_proxy_pass",

+ 4 - 0
src/models/nginx.ts

@@ -165,6 +165,10 @@ export type INginxStream = {
    * 是否启用
    */
   enable?: boolean
+  /**
+   * 是否监听TCP,但是isSteam=true时有效
+   */
+  isUdp?: boolean;
 }
 
 export type PNginxServer = Partial<INginxServer>

+ 1 - 1
src/pages/nginx/components/gzip/index.tsx

@@ -31,7 +31,7 @@ export const GzipInput = ({value, onChange}:AutoTypeInputProps) => {
 
   const triggerChange = (values: any)=>{
     const lines:string[] = []
-    if (data?.gzip){
+    if (values?.gzip){
       lines.push(`gzip      on;`)
       Object.keys(values).forEach(k=>{
         let v = values[k];

+ 2 - 0
src/pages/nginx/components/log/config.json

@@ -3,6 +3,7 @@
     "title": "error_log",
     "type": "object",
     "key": "error_log",
+    "required": false,
     "items": [
       {
         "title": "path",
@@ -25,6 +26,7 @@
     "title": "access_log",
     "type": "object",
     "key": "access_log",
+    "required": false,
     "items": [
       {
         "title": "path",

+ 31 - 25
src/pages/nginx/components/log/index.tsx

@@ -5,12 +5,12 @@
  */
 import {registerInput} from '../basic'
 import {
-    AutoTypeInputProps,
-    FormColumnType,
-    noRequired,
-    ObjectInput,
-    DataValidatorConfig,
-    AutoColumn
+  AutoTypeInputProps,
+  FormColumnType,
+  noRequired,
+  ObjectInput,
+  DataValidatorConfig,
+  AutoColumn, isNull
 } from "planning-tools";
 import {Button, Tooltip} from "antd";
 import CONFIG from './config.json'
@@ -20,6 +20,7 @@ import {useEffect, useMemo, useRef, useState} from "react";
 import {QuestionCircleOutlined} from "@ant-design/icons";
 import {useAppSelector} from "../../../../store";
 import {HttpConfData} from "../../types.ts";
+import {cloneDeep} from "lodash";
 
 type AccessLogData = {
     path: string
@@ -50,8 +51,10 @@ export const ErrorLog = ({value, column, onChange, columns}: ErrorLogProps) => {
         if (columns){
             return columns
         }
-        const col: FormColumnType = {...CONFIG.error_log};
-        col.required = column.required;
+        const col: FormColumnType = cloneDeep(CONFIG.error_log);
+        if (!isNull(column.required)){
+          col.required = column.required;
+        }
         return col
     },[columns, column])
 
@@ -89,31 +92,34 @@ export const AccessLog = (props: AutoTypeInputProps) => {
 
     const nginx = useAppSelector(state => state.nginx.current);
 
-    const options = useMemo(()=>{
+    const column = useMemo(()=>{
       const isStream = (props.column as any).stream;
-        if (!nginx?.httpData){
-            return [ isStream ? 'tcp_format' : 'main']
-        }
         let result: string[] = [];
-        try {
+        if (nginx?.httpData){
+          try {
             const httpData = JSON.parse(nginx?.httpData) as HttpConfData ?? {};
-            const list = (props.column as any).stream ? httpData["stream.log_format"] : httpData["http.log_format"] || []
-          result= list.filter(item=>item.name && item.content)
-                .map(item=>item.name)
-        }catch (e) {
+            const list = isStream ? httpData["stream.log_format"] : httpData["http.log_format"] || []
+            result= list.filter(item=>item.name && item.content)
+                .map(item=>item.name);
+          }catch (e) {
             console.log('AccessLog parse httpData fail',e)
+          }
         }
         if (result.length == 0){
           result.push(isStream ? 'tcp_format' : 'main')
         }
-        return result
+
+      const col: FormColumnType = cloneDeep(CONFIG.access_log);
+        if (!isNull(props.column.required)){
+          col.required = props.column.required;
+        }
+      const level = col.items?.find(item=>item.key === 'level');
+      level && (level.option = result)
+      console.log('accessLog=>',col, props.column.required)
+      return col
     },[nginx, props.column])
 
-    const col: FormColumnType = {...CONFIG.access_log};
-    col.required = props.column.required;
-    const level = col.items?.find(item=>item.key === 'level');
-    level && (level.option = options)
-    return (<ErrorLog {...props} columns={col} />)
+    return (<ErrorLog {...props} columns={column} />)
 }
 
 
@@ -121,7 +127,7 @@ registerInput('access_log', AccessLog)
 registerInput('error_log',ErrorLog)
 
 const validateLog = (value: any, config: AutoColumn) => {
-    if (noRequired(config.required) && !value){
+    if (noRequired(config.required) && !value?.data){
         return
     }
     if (!value || !value.data){
@@ -137,7 +143,7 @@ const validateLog = (value: any, config: AutoColumn) => {
 }
 
 const validateAccessLog = (value: any, config: AutoColumn) => {
-    if (noRequired(config.required) && !value){
+    if (noRequired(config.required) && !value?.data){
         return
     }
     if (!value || !value.data){

+ 5 - 1
src/pages/nginx/utils/index.ts

@@ -69,7 +69,11 @@ export const renderStream = (server: Partial<INginxServer>) =>{
       return
     }
     lines.push(`    server {`)
-    lines.push(`        listen ${server.listen};`)
+    if (server.isUdp){
+      lines.push(`        listen ${server.listen} udp;`)
+    }else {
+      lines.push(`        listen ${server.listen};`)
+    }
     lines.push(`        proxy_pass ${server.proxy_pass};`)
     if (server.proxy_connect_timeout){
       lines.push(`        proxy_connect_timeout ${server.proxy_connect_timeout}s;`)