From 0637e6c33b334896d0bb07231c8c3a9914130c56 Mon Sep 17 00:00:00 2001 From: Matthew Campbell Date: Thu, 2 Nov 2017 17:28:14 +0700 Subject: [PATCH] rpc proxy will now send html back also --- gateway/appmgmt.go | 12 +++++++++--- gateway/gateway.go | 1 + gateway/http.go | 8 ++++++-- proxy_runner.conf | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/gateway/appmgmt.go b/gateway/appmgmt.go index 31b919e..1ba0396 100644 --- a/gateway/appmgmt.go +++ b/gateway/appmgmt.go @@ -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 { @@ -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 { diff --git a/gateway/gateway.go b/gateway/gateway.go index cc8988e..1d2b063 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -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 } diff --git a/gateway/http.go b/gateway/http.go index 73555f7..f9b5f55 100644 --- a/gateway/http.go +++ b/gateway/http.go @@ -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" @@ -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 diff --git a/proxy_runner.conf b/proxy_runner.conf index 3993631..379d494 100644 --- a/proxy_runner.conf +++ b/proxy_runner.conf @@ -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