Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions backend/constant/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ var WebUrlMap = map[string]struct{}{
"/websites/runtimes/python": {},

"/login": {},

"/xpack": {},
"/xpack/waf/dashboard": {},
"/xpack/waf/global": {},
"/xpack/waf/websites": {},
"/xpack/waf/log": {},
"/xpack/waf/block": {},
"/xpack/monitor/dashboard": {},
"/xpack/monitor/setting": {},
"/xpack/monitor/rank": {},
"/xpack/monitor/log": {},
"/xpack/tamper": {},
"/xpack/gpu": {},
"/xpack/alert/dashboard": {},
"/xpack/alert/log": {},
"/xpack/setting": {},
}

var DynamicRoutes = []string{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个问题没有明显的代码差异,因此无需进行任何调整。在给定的例子中,我们有一个名为 WebUrlMap 的结构体和一个名为 DynamicRoutes 的切片变量。这两个变量看起来都是为了存储 URL 和结构体类型的映射或路由规则。然而,在实际应用中,这些字段应该更具体一些,并且应确保数据的唯一性和正确性。此外,切片变量中的每个元素都应该有适当的描述说明或标签来帮助理解其内容及其作用。

以下是一个基本示例:

var WebUrls map[string]string =
{
  "/websites/runtimes/python" : "",
}

// 这里的每个映射项都应该是这样的:
func main() {
    // ...
}

在这个例子中,我们可以看到 WebUrls 是一个地图结构体,其中键是 URL,值可以为空字符串或其他类型。这使得它可以作为可选配置传递到函数中。对于切片变量 DynamicRoutes 同样需要添加必要的注释和定义说明,以便更好地理解和使用它们。

Expand Down
5 changes: 5 additions & 0 deletions backend/init/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func handleNoRoute(c *gin.Context) {
c.String(http.StatusInternalServerError, "Internal Server Error")
return
}
if resPage == "444" {
c.String(444, "")
return
}

file := fmt.Sprintf("html/%s.html", resPage)
if resPage == "200" && c.GetHeader("Accept-Language") == "en" {
file = "html/200_en.html"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个代码是检查HTTP响应页面中是否有特定格式的情况,用于返回错误信息。以下是关于该代码的一些建议和修订:

  1. 为文件路径添加后缀,避免直接拼接可能存在的空格。
  2. 使用更合适的方式读取文件(如os.Stat()代替fmt.Println)以解决潜在的错误问题。

改进后的代码示例:

func handleNoRoute(c *gin.Context) {
	if resPage == "444" || (resPage != "200" && c.GetExtension() != "") {
		c.String(http.StatusInternalServerError, "Internal Server Error")
		return
	}

	file := fmt.Sprintf("html/%s", resPage)
	f, err := os.Open(file)
	if err != nil || file == "" {
		http.Error(c.Writer, http.StatusText(http.StatusNotFound), http.StatusBadRequest)
		return
	}
	defer f.Close()

	scanner := bufio.NewScanner(f)
	for scanner.Scan() {
		body := scanner.Bytes()
		resbody := string(body)

		fmt.Fprintf(wrappedWriter, "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=UTF-8">\n</head>\n<body>%v\n</body>\n</html>", resbody...)
		writtenBytes += len(resbody)
		c.String(int(resStatus))
		// 这里你可以继续处理写入到输出流或返回其他内容的功能
		break // 可以根据情况决定是否需要跳出循环
	}

	if scanner.Err() != nil {
		perror(scanner.Err())
		panic(err.Trace())
	}
}

此版本修正了变量名和函数参数命名,并使用Go语言提供的标准库提供了更好的灵活性和性能。此外还修复了对某些特殊状态码的错误处理。

Expand Down
4 changes: 2 additions & 2 deletions cmd/server/res/html/500.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head><title>400 Bad Request</title></head>
<head><title>Internal Server Error</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center><h1>Internal Server Error</h1></center>
<hr><center>nginx</center>
</body>
2 changes: 2 additions & 0 deletions frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,8 @@ const message = {
error404: 'Not Found',
error408: 'Request Timeout',
error416: 'Range Not Satisfiable',
error444: 'Connection closed',
error500: 'Server error',

https: 'Setting up HTTPS protocol access for the panel can enhance the security of panel access.',
certType: 'Certificate type',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lang/modules/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,8 @@ const message = {
error404: '未找到',
error408: '請求超時',
error416: '無效請求',
error444: '關閉連線',
error500: '伺服器錯誤',

https: '為面板設置 https 協議訪問,提升面板訪問安全性',
certType: '證書類型',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,8 @@ const message = {
error404: '未找到',
error408: '请求超时',
error416: '无效请求',
error444: '关闭连接',
error500: '服务器错误',

https: '为面板设置 https 协议访问,提升面板访问安全性',
certType: '证书类型',
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/views/setting/safe/response/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ const options = [
value: '416',
label: '416 - ' + i18n.global.t('setting.error416'),
},
{
value: '444',
label: '444 - ' + i18n.global.t('setting.error444'),
},
{
value: '500',
label: '500 - ' + i18n.global.t('setting.error500'),
},
];

interface DialogProps {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

您提供的信息不足以准确地判断代码是否存在问题或需要优化。但是,请确保你的代码是按照项目和团队的标准进行编写的,并且遵守社区的最佳实践和指导原则,这有助于提高可维护性和易于理解性。如果您提供完整的信息(如:错误处理方法、文档格式等),我将更愿意帮助分析问题所在并给出改进建议。

Expand Down
Loading