Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
add index page
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Feb 8, 2017
1 parent 68e1adb commit 8e277fd
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
18 changes: 18 additions & 0 deletions .fsw.yml
Original file line number Diff line number Diff line change
@@ -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
52 changes: 42 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, `<!doctype html>

indexContent = `<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>A static page</title>
<link rel="stylesheet" href="/stylesheets/main.css">
<style>
body {
padding: 50px 80px;
margin: 0px;
}
pre {
font-family: "Courier New";
padding: 10px;
border: 1px solid gray;
}
</style>
</head>
<body>
<h1>WDA Proxy</h1>
Expand All @@ -37,9 +42,32 @@ func NewReverseProxyHandlerFunc(targetURL *url.URL) http.HandlerFunc {
<li><a href="/inspector">Inspector</a></li>
<li><a href="/status">Status</a></li>
</ul>
<pre id="status"></pre>
</div>
</body>
</html>`)
<script src="//cdn.jsdelivr.net/jquery/3.1.1/jquery.min.js"></script>
<script>
var pre = document.getElementById("status");
$.ajax({
url: "/status",
dataType: "json",
success: function(ret){
pre.innerHTML = JSON.stringify(ret, null, " ");
},
error: function(xhr, status, err){
pre.innerHTML = xhr.status + " " + err;
pre.style.color = "red";
}
})
</script>
</html>`
)

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)
Expand All @@ -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)
Expand All @@ -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()
}()

Expand Down

0 comments on commit 8e277fd

Please sign in to comment.