diff --git a/.fsw.yml b/.fsw.yml new file mode 100644 index 0000000..bc5767e --- /dev/null +++ b/.fsw.yml @@ -0,0 +1,18 @@ +desc: Auto generated by fswatch [wdaproxy] +triggers: +- name: "" + pattens: + - '**/*.go' + - '**/*.c' + - '**/*.py' + env: + DEBUG: "1" + cmd: go build && ./wdaproxy -p 8200 + shell: true + delay: 100ms + stop_timeout: 500ms + signal: KILL + kill_signal: "" +watch_paths: +- . +watch_depth: 0 diff --git a/main.go b/main.go index 1f39a9d..d7eaf24 100644 --- a/main.go +++ b/main.go @@ -17,18 +17,23 @@ var ( version = "develop" lisPort = 8100 udid string -) - -func NewReverseProxyHandlerFunc(targetURL *url.URL) http.HandlerFunc { - httpProxy := httputil.NewSingleHostReverseProxy(targetURL) - return func(rw http.ResponseWriter, r *http.Request) { - if r.RequestURI == "/" { - io.WriteString(rw, ` + + indexContent = ` A static page - +

WDA Proxy

@@ -37,9 +42,32 @@ func NewReverseProxyHandlerFunc(targetURL *url.URL) http.HandlerFunc {
  • Inspector
  • Status
  • +
    
       
     
    -`)
    +
    +
    +`
    +)
    +
    +func NewReverseProxyHandlerFunc(targetURL *url.URL) http.HandlerFunc {
    +	httpProxy := httputil.NewSingleHostReverseProxy(targetURL)
    +	return func(rw http.ResponseWriter, r *http.Request) {
    +		if r.RequestURI == "/" {
    +			io.WriteString(rw, indexContent)
     			return
     		}
     		httpProxy.ServeHTTP(rw, r)
    @@ -63,6 +91,7 @@ func main() {
     	if err != nil {
     		log.Fatal(err)
     	}
    +	log.Printf("get freeport %d", freePort)
     
     	go func() {
     		log.Printf("launch tcp-proxy, listen on %d", lisPort)
    @@ -73,7 +102,10 @@ func main() {
     	}()
     	go func() {
     		log.Printf("launch iproxy, device udid(%s)", udid)
    -		c := exec.Command("iproxy", strconv.Itoa(freePort), strconv.Itoa(lisPort), udid)
    +		c := exec.Command("iproxy", strconv.Itoa(freePort), "8100")
    +		if udid != "" {
    +			c.Args = append(c.Args, udid)
    +		}
     		errC <- c.Run()
     	}()