All checks were successful
CI / build (push) Successful in 2m41s
Split monolithic app.go into focused modules (dashboard, chat, workflow, config, agents, terminal, commands, handlers). Add proper error handling for installer commands, proxy pipes, and MCP config parsing. Fix daemon channel buffer, cap orchestrator history, compile think regex once, and set HTTP timeouts on preview server. Improve CI with Go module caching, dependency download step, and test stage with race detection. 😘 Generated with Crush Assisted-by: GLM-5-Turbo via Crush <crush@charm.land>
80 lines
1.5 KiB
Go
80 lines
1.5 KiB
Go
package preview
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"runtime"
|
|
"time"
|
|
)
|
|
|
|
type PreviewServer struct {
|
|
dir string
|
|
server *http.Server
|
|
}
|
|
|
|
func NewPreviewServer(dir string) *PreviewServer {
|
|
return &PreviewServer{dir: dir}
|
|
}
|
|
|
|
func (p *PreviewServer) Start(port int) error {
|
|
fs := http.FileServer(http.Dir(p.dir))
|
|
mux := http.NewServeMux()
|
|
mux.Handle("/", fs)
|
|
|
|
p.server = &http.Server{
|
|
Addr: fmt.Sprintf("127.0.0.1:%d", port),
|
|
Handler: mux,
|
|
ReadTimeout: 30 * time.Second,
|
|
WriteTimeout: 30 * time.Second,
|
|
}
|
|
|
|
go func() {
|
|
if err := p.server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
|
fmt.Printf("Preview server error: %s\n", err)
|
|
}
|
|
}()
|
|
|
|
url := fmt.Sprintf("http://127.0.0.1:%d", port)
|
|
fmt.Printf("Preview server running at %s\n", url)
|
|
|
|
return openBrowser(url)
|
|
}
|
|
|
|
func (p *PreviewServer) Stop() error {
|
|
if p.server != nil {
|
|
return p.server.Close()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func CreatePreviewFile(dir, filename, content string) error {
|
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
|
return err
|
|
}
|
|
return os.WriteFile(filepath.Join(dir, filename), []byte(content), 0644)
|
|
}
|
|
|
|
func openBrowser(url string) error {
|
|
var cmd string
|
|
var args []string
|
|
|
|
switch runtime.GOOS {
|
|
case "linux":
|
|
cmd = "xdg-open"
|
|
args = []string{url}
|
|
case "darwin":
|
|
cmd = "open"
|
|
args = []string{url}
|
|
case "windows":
|
|
cmd = "cmd"
|
|
args = []string{"/c", "start", url}
|
|
default:
|
|
return fmt.Errorf("unsupported platform")
|
|
}
|
|
|
|
return exec.Command(cmd, args...).Start()
|
|
}
|