Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
proxy uiautomator server localhost:9008
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Sep 22, 2017
1 parent 559e31e commit 7114955
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"log"
"net"
"net/http"
"net/http/httputil"
"net/url"
"os"
"os/exec"
"os/signal"
Expand Down Expand Up @@ -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,
})
})

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 7114955

Please sign in to comment.