Skip to content

Commit

Permalink
rpc proxy will now send html back also
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkanwisher committed Nov 2, 2017
1 parent 19dd009 commit 0637e6c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
12 changes: 9 additions & 3 deletions gateway/appmgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,21 @@ func (g *Gateway) downloadS3CompatibleFile(applicationZipPath, outputPath string
return nil
}

func (g *Gateway) getextractedDir() string {
if g.guid == "" {
g.guid = uuid.NewV4().String()
}
return filepath.Join(g.cfg.TmpDir, g.guid)
}

func (g *Gateway) downloadAndExtractApp(applicationZipPath string) error {
var err error

guid := uuid.NewV4().String()
if strings.Index(applicationZipPath, "s3://") == 0 {
return errors.New("We don't support s3 urls yet")
}

appDir := filepath.Join(g.cfg.TmpDir, guid)
appDir := g.getextractedDir()
log.WithField("dir", g.cfg.TmpDir).Debug("creating folder")
err = os.MkdirAll(g.cfg.TmpDir, 0766)
if err != nil {
Expand All @@ -50,7 +56,7 @@ func (g *Gateway) downloadAndExtractApp(applicationZipPath string) error {
//If we need to download from digitalocean
if strings.Index(applicationZipPath, "do://") == 0 {
dataPath := strings.Split(applicationZipPath, "do://")[1]
outFile = filepath.Join(g.cfg.TmpDir, guid+".zip")
outFile = filepath.Join(g.cfg.TmpDir, g.guid+".zip")
log.WithField("dataPath", dataPath).WithField("outFile", outFile).Debug("download file from remote server")
err = g.downloadS3CompatibleFile(dataPath, outFile)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type Gateway struct {
sync.RWMutex // for the contracts
StopChannel chan bool
appDir string
guid string //unique id for this instance
cfg *config.RPCConfig
contracts []*Contract //Only access with helper methods, cause its not threadsafe
}
Expand Down
8 changes: 6 additions & 2 deletions gateway/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http/httputil"

"github.com/containous/traefik/log"
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
"github.com/loomnetwork/dashboard/middleware"
Expand Down Expand Up @@ -108,9 +109,12 @@ func (g *Gateway) routerInitialize(r *gin.Engine) {
//We prefix our apis with underscore so there is no conflict with the Web3 RPC APOs
r.POST("/_loom/accounts", g.LoomAccounts) //Returns accounts and private keys for this test network
r.POST("/_loom/contracts", g.LoomContracts) //Returns what contracts have been deployed to the smart contract

// Web3 RPCs
r.NoRoute(g.Web3CatchAll)
r.POST("/", g.Web3CatchAll)

p := g.getextractedDir() + "/static"
s := static.Serve("/", static.LocalFile(p, true))
r.Use(s)
}

//TODO maybe split http to a seperate class
Expand Down
2 changes: 1 addition & 1 deletion proxy_runner.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ root: cmd/rpc_proxy/rpc_proxy.go
tmp_path: ./tmp
build_name: runner-build-proxy
build_log: runner-build-proxy-errors.log
environ: PRIVATE_KEY_JSON_PATH=data.json,SPAWN_NETWORK=/usr/local/bin/node tmp/testrpc/build/cli.node.js --acctKeys data.json,PRE_KILL=true
environ: PRIVATE_KEY_JSON_PATH=data.json,SPAWN_NETWORK=/usr/local/bin/node tmp/testrpc/build/cli.node.js,PRE_KILL=true
valid_ext: .go, .tpl, .tmpl, .html
no_rebuild_ext: .tpl, .tmpl, .html
ignored: assets, tmp, node_modules, vendor
Expand Down

0 comments on commit 0637e6c

Please sign in to comment.