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
1 change: 1 addition & 0 deletions agent/cmd/server/nginx_conf/proxy.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ location ^~ /test {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_http_version 1.1;

add_header X-Cache $upstream_cache_status;
Expand Down
3 changes: 0 additions & 3 deletions core/cmd/server/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@ var IndexHtml embed.FS
//go:embed assets/*
var Assets embed.FS

//go:embed index.html
var IndexByte []byte

//go:embed favicon.png
var Favicon embed.FS
Copy link
Member

Choose a reason for hiding this comment

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

There is no apparent issue with the provided code. Here are some minor improvements for better clarity:

//go:embed assets/*
var Assets embed.FS

//go:embed favicon.png
var Favicon embed.FS

These two lines can be merged for cleaner syntax while maintaining the same functionality. It's a matter of preference and style choice.

Note: The IndexByte variable was removed because embedding multiple files of the same name within an embed directive results in only one file being embedded and accessible via that name. If you were to include index.html separately later on, it would conflict with this single entry under "assets".

If preserving both versions (Assets for other HTML files and IndexByte for a specific index.html) is necessary, you don't need to remove anything - they simply share different names but contain the same set of files.

7 changes: 6 additions & 1 deletion core/utils/security/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ func CheckSecurity(c *gin.Context) bool {
func ToIndexHtml(c *gin.Context) {
c.Writer.Header().Set("Content-Type", "text/html; charset=utf-8")
c.Writer.WriteHeader(http.StatusOK)
_, _ = c.Writer.Write(web.IndexByte)
data, err := web.IndexHtml.ReadFile("index.html")
if err != nil {
c.String(http.StatusInternalServerError, "index.html not found")
return
}
_, _ = c.Writer.Write(data)
c.Writer.Flush()
}

Copy link
Member

Choose a reason for hiding this comment

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

The changes you've made seem largely correct, although there is a small issue with the return type of ToIndexHtml. If it should write HTML directly to HTTP response instead of returning an error or boolean value, consider modifying its type accordingly.

Here's your updated code:

func ToIndexHtml(c *gin.Context) {
    c.Writer.Header().Set("Content-Type", "text/html; charset=utf-8")
    c.Writer.WriteHeader(http.StatusOK)

    data, err := web.IndexHtml.ReadFile("index.html")
    if err != nil {
        c.String(http.StatusInternalServerError, "index.html not found")
        return
    }

    _, _ = c.Writer.Write(data)
	c.Writer.Flush()
}

Potential Improvements:

  1. Error Handling: Ensure proper error handling for other cases (e.g., directory traversal attacks).
  2. Performance: For larger files, consider streaming the file content rather than reading it all into memory at once.
  3. Caching: Implement caching strategies if this method is executed frequently by different clients.
  4. Security: Be cautious when loading static assets from disk, especially in production environments.

These enhancements ensure better robustness and performance of the function.

Expand Down
Loading