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

feat: embedded web ui #1182

wants to merge 6 commits into from

Conversation

faddat
Copy link
Contributor

@faddat faddat commented Feb 23, 2024

  • embed web ui
  • make the server a little more configurable

1. Summary

Fixes # (issue)

2.Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

3. Implementation details

4. How to test/use

5. Checklist

  • Does the Readme need to be updated?

6. Limitations (optional)

7. Future Work (optional)

Summary by CodeRabbit

  • New Features
    • Introduced a Web UI functionality for enhanced user interaction, accessible through port 8080.

Copy link

vercel bot commented Feb 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
quicksilver ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 1, 2024 6:14pm

Copy link
Contributor

coderabbitai bot commented Feb 23, 2024

Walkthrough

The recent update introduces a web UI functionality to the application by embedding static files to be served through a basic HTTP server. This significant enhancement facilitates user interaction by allowing access to a web interface, potentially transforming how users interact with the application and manage its features.

Changes

File(s) Change Summary
cmd/quicksilverd/main.go Added webui.UI() to start the web server for web UI.
web-ui/embed.go Introduced functionality to serve an embedded web UI using the Go embed package.

Related issues

  • Embed the web ui #943: The changes directly address the proposal to embed the web UI into the application binaries, enhancing decentralization by avoiding a single point of failure for accessing the web UI.

🐇✨

In the code's burrow, deep and wide,
A web UI, now snugly inside.
Through port 8080, it peeks,
Serving pages, for weeks and weeks.
A rabbit's work, so deft and sly,
Bringing the web UI nigh.
🌐🚀


Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

)

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

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6c2db0c and 4904d3b.
Files ignored due to path filters (1)
  • go.work.sum is excluded by: !**/*.sum
Files selected for processing (2)
  • cmd/quicksilverd/main.go (1 hunks)
  • web-ui/embed.go (1 hunks)
Additional comments: 3
web-ui/embed.go (2)
  • 3-7: The import statements are correctly defined, including essential packages for embedding files and handling HTTP requests.
  • 10-11: Using Go's embed package to serve static files is a good practice for embedding a web UI. This approach ensures that the web UI's static files are packaged with the application binary, simplifying deployment.
cmd/quicksilverd/main.go (1)
  • 13-13: The import statement correctly includes the web-ui package, allowing the main function to start the web UI server.

Comment on lines +13 to +27
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)
}
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
}

)

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.
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.

@joe-bowman
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants