From 7114955f60c129b0a8d29a03e5bd9fa958988b68 Mon Sep 17 00:00:00 2001 From: shengxiang Date: Fri, 22 Sep 2017 21:05:51 +0800 Subject: [PATCH] proxy uiautomator server localhost:9008 --- main.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index e4eb90f..387f1cb 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,8 @@ import ( "log" "net" "net/http" + "net/http/httputil" + "net/url" "os" "os/exec" "os/signal" @@ -316,10 +318,10 @@ func ServeHTTP(port int) error { command = r.FormValue("c") } output, err := exec.Command("sh", "-c", command).CombinedOutput() - log.Println(err) w.Header().Set("Content-Type", "application/json; charset=UTF-8") json.NewEncoder(w).Encode(map[string]interface{}{ "output": string(output), + "error": err, }) }) @@ -445,6 +447,10 @@ func ServeHTTP(port int) error { }() }) + target, _ := url.Parse("http://127.0.0.1:9008") + uiautomatorProxy := httputil.NewSingleHostReverseProxy(target) + http.Handle("/jsonrpc/0", uiautomatorProxy) + http.Handle("/ping", uiautomatorProxy) http.Handle("/", m) httpServer = &http.Server{ Addr: ":" + strconv.Itoa(port), @@ -472,6 +478,8 @@ func main() { showVersion := flag.Bool("v", false, "show version") flag.Parse() + log.SetFlags(log.LstdFlags | log.Lshortfile) + if *showVersion { fmt.Println(version) return @@ -500,7 +508,6 @@ func main() { os.Stdin = nil log.SetOutput(f) - log.SetFlags(log.LstdFlags | log.Lshortfile) log.Println("Ignore SIGUP") signal.Ignore(syscall.SIGHUP)