Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: embedded web ui #1182

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 2 additions & 0 deletions cmd/quicksilverd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

"github.com/quicksilver-zone/quicksilver/app"
cmdcfg "github.com/quicksilver-zone/quicksilver/cmd/config"
webui "github.com/quicksilver-zone/quicksilver/web-ui"
)

func main() {
cmdcfg.SetupConfig()
cmdcfg.RegisterDenoms()
webui.UI() // Start the web server. TODO: ensure that this is easy for operators to turn off, and that it handles cors or whatever.

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
Copy link
Contributor

Choose a reason for hiding this comment

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

The call to webui.UI() to start the web server is placed appropriately in the main function. However, there are a couple of considerations:

  1. Error Handling: The UI function currently does not return an error, but if it's modified to return an error (as suggested in the review of embed.go), the error should be handled here to ensure that any issues starting the web server are appropriately addressed.
  2. Configurability and Security Note: The TODO comment mentions making the web server easy to turn off and handling CORS. It's crucial to follow up on these points to ensure that the application can be securely and flexibly configured according to the deployment environment.
-	webui.UI() // Start the web server.  TODO: ensure that this is easy for operators to turn off, and that it handles cors or whatever.
+	err := webui.UI() // Start the web server.
+	if err != nil {
+		fmt.Println("Failed to start the web UI server:", err)
+		return
+	}
// TODO: Ensure that the web server can be easily turned off through configuration and that CORS is appropriately handled.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
webui.UI() // Start the web server. TODO: ensure that this is easy for operators to turn off, and that it handles cors or whatever.
err := webui.UI() // Start the web server.
if err != nil {
fmt.Println("Failed to start the web UI server:", err)
return
}
// TODO: Ensure that the web server can be easily turned off through configuration and that CORS is appropriately handled.


userHomeDir, err := os.UserHomeDir()
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions go.work.sum

This file was deleted.

Binary file modified web-ui/bun.lockb
Binary file not shown.
28 changes: 28 additions & 0 deletions web-ui/embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package webui

import (
"embed"
"fmt"
"net/http"
"time"
)

//go:embed out/*

Check failure on line 10 in web-ui/embed.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, linux)

pattern out/*: no matching files found

Check failure on line 10 in web-ui/embed.go

View workflow job for this annotation

GitHub Actions / Analyze

pattern out/*: no matching files found

Check failure on line 10 in web-ui/embed.go

View workflow job for this annotation

GitHub Actions / lint

pattern out/*: no matching files found (typecheck)

Check failure on line 10 in web-ui/embed.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, linux)

pattern out/*: no matching files found

Check failure on line 10 in web-ui/embed.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

pattern out/*: no matching files found

Check failure on line 10 in web-ui/embed.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, windows)

pattern out/*: no matching files found

Check failure on line 10 in web-ui/embed.go

View workflow job for this annotation

GitHub Actions / test quicksilver (darwin, arm64)

pattern out/*: no matching files found

Check failure on line 10 in web-ui/embed.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, darwin)

pattern out/*: no matching files found
var webFS embed.FS

func UI() {
http.Handle("/", http.FileServer(http.FS(webFS)))

server := &http.Server{
Addr: ":8080",
Handler: nil, // Use default mux
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 15 * time.Second,
}

err := server.ListenAndServe()
if err != nil {
fmt.Println("Error starting embedded web app server: ", err)
}
Comment on lines +13 to +27
Copy link
Contributor

Choose a reason for hiding this comment

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

The UI function correctly sets up an HTTP server to serve the embedded web UI. However, there are a few areas for improvement:

  1. Error Handling: The error from ListenAndServe is printed but not returned. It's generally a good practice to return errors to the caller, allowing for more flexible error handling.
  2. Hardcoded Port: The server listens on a hardcoded port :8080. Consider making the port configurable through environment variables or a configuration file to enhance flexibility.
  3. Default Handler: The comment on line 18 mentions using the default mux, but it's implicitly done by passing nil as the Handler. It might be helpful to explicitly mention that http.DefaultServeMux is used when nil is passed for clarity.
func UI() error {
	http.Handle("/", http.FileServer(http.FS(webFS)))

+	port := os.Getenv("WEB_UI_PORT")
+	if port == "" {
+		port = "8080" // Default port
+	}
	server := &http.Server{
-		Addr:         ":8080",
+		Addr:         ":" + port,
		Handler:      nil, // Use default mux (http.DefaultServeMux)
		ReadTimeout:  5 * time.Second,
		WriteTimeout: 10 * time.Second,
		IdleTimeout:  15 * time.Second,
	}

	err := server.ListenAndServe()
	if err != nil {
		fmt.Println("Error starting embedded web app server: ", err)
+		return err
	}
+	return nil
}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func UI() {
http.Handle("/", http.FileServer(http.FS(webFS)))
server := &http.Server{
Addr: ":8080",
Handler: nil, // Use default mux
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 15 * time.Second,
}
err := server.ListenAndServe()
if err != nil {
fmt.Println("Error starting embedded web app server: ", err)
}
func UI() error {
http.Handle("/", http.FileServer(http.FS(webFS)))
port := os.Getenv("WEB_UI_PORT")
if port == "" {
port = "8080" // Default port
}
server := &http.Server{
Addr: ":" + port,
Handler: nil, // Use default mux (http.DefaultServeMux)
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 15 * time.Second,
}
err := server.ListenAndServe()
if err != nil {
fmt.Println("Error starting embedded web app server: ", err)
return err
}
return nil
}

}
Loading