Skip to content

Commit

Permalink
Minor improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
BencicAndrej committed Nov 8, 2018
1 parent 3ef00b0 commit 163962b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.idea

# Compiled binary
/tenderly-cli

dist/*
build/*
9 changes: 4 additions & 5 deletions cmd/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package proxy
import (
"flag"
"fmt"
"log"
"net/http"
"net/http/httputil"
"net/url"
Expand All @@ -15,9 +14,9 @@ type Prox struct {
}

func NewProxy(target string) *Prox {
url, _ := url.Parse(target)
targetUrl, _ := url.Parse(target)

return &Prox{target: url, proxy: httputil.NewSingleHostReverseProxy(url)}
return &Prox{target: targetUrl, proxy: httputil.NewSingleHostReverseProxy(targetUrl)}
}

func (p *Prox) handle(w http.ResponseWriter, r *http.Request) {
Expand All @@ -28,7 +27,7 @@ func (p *Prox) handle(w http.ResponseWriter, r *http.Request) {

}

func Start(targetSchema, targetHost, targetPort, proxyHost, proxyPort, path, network string) {
func Start(targetSchema, targetHost, targetPort, proxyHost, proxyPort, path, network string) error {
flag.Parse()

fmt.Println(fmt.Sprintf("server will run on %s:%s", proxyHost, proxyPort))
Expand All @@ -41,7 +40,7 @@ func Start(targetSchema, targetHost, targetPort, proxyHost, proxyPort, path, net

// server redirection
http.HandleFunc("/", proxy.handle)
log.Fatal(http.ListenAndServe(proxyHost+":"+proxyPort, nil))
return http.ListenAndServe(proxyHost+":"+proxyPort, nil)
}

func Server(w http.ResponseWriter, r *http.Request) {
Expand Down
8 changes: 5 additions & 3 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/spf13/cobra"
"github.com/tenderly/tenderly-cli/cmd/proxy"
"log"
)

var targetHost string
Expand All @@ -20,8 +21,7 @@ func init() {
proxyCmd.PersistentFlags().StringVar(&targetPort, "target-port", "8545", "Blockchain rpc port.")
proxyCmd.PersistentFlags().StringVar(&proxyHost, "proxy-host", "127.0.0.1", "Proxy host.")
proxyCmd.PersistentFlags().StringVar(&proxyPort, "proxy-port", "9545", "Proxy port.")
proxyCmd.PersistentFlags().StringVar(&path, "path", "", "Path to the project build folder.")
proxyCmd.PersistentFlags().StringVar(&network, "network", "", "Network id.")
proxyCmd.PersistentFlags().StringVar(&path, "path", ".", "Path to the project build folder.")

rootCmd.AddCommand(proxyCmd)
rootCmd.AddCommand(versionCmd)
Expand All @@ -44,6 +44,8 @@ var proxyCmd = &cobra.Command{
Use: "proxy",
Short: "Proxy",
Run: func(cmd *cobra.Command, args []string) {
proxy.Start(targetSchema, targetHost, targetPort, proxyHost, proxyPort, path, network)
if err := proxy.Start(targetSchema, targetHost, targetPort, proxyHost, proxyPort, path, network); err != nil {
log.Fatal(err)
}
},
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func Execute() {
CurrentCLIVersion = version
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(0)
os.Exit(1)
}
}

Expand Down

0 comments on commit 163962b

Please sign in to comment.