aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/swarm.go
diff options
context:
space:
mode:
authorMaran <maran.hidskes@gmail.com>2017-01-05 18:57:41 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-01-05 18:57:41 +0800
commitf087633efdf42f23ada99a5750af30320a7905a8 (patch)
treeb905d58611b342650657c20810aa9cc1d44b73e2 /swarm/swarm.go
parentbbce726c8a85e72141d9d7e690711738c09ede3b (diff)
downloadgo-tangerine-f087633efdf42f23ada99a5750af30320a7905a8.tar
go-tangerine-f087633efdf42f23ada99a5750af30320a7905a8.tar.gz
go-tangerine-f087633efdf42f23ada99a5750af30320a7905a8.tar.bz2
go-tangerine-f087633efdf42f23ada99a5750af30320a7905a8.tar.lz
go-tangerine-f087633efdf42f23ada99a5750af30320a7905a8.tar.xz
go-tangerine-f087633efdf42f23ada99a5750af30320a7905a8.tar.zst
go-tangerine-f087633efdf42f23ada99a5750af30320a7905a8.zip
swarm/api/http: add support for CORS headers (#3388)
Diffstat (limited to 'swarm/swarm.go')
-rw-r--r--swarm/swarm.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/swarm/swarm.go b/swarm/swarm.go
index 7e38944de..4b3621aff 100644
--- a/swarm/swarm.go
+++ b/swarm/swarm.go
@@ -52,6 +52,7 @@ type Swarm struct {
hive *network.Hive // the logistic manager
backend chequebook.Backend // simple blockchain Backend
privateKey *ecdsa.PrivateKey
+ corsString string
swapEnabled bool
}
@@ -71,7 +72,7 @@ func (self *Swarm) API() *SwarmAPI {
// creates a new swarm service instance
// implements node.Service
-func NewSwarm(ctx *node.ServiceContext, backend chequebook.Backend, config *api.Config, swapEnabled, syncEnabled bool) (self *Swarm, err error) {
+func NewSwarm(ctx *node.ServiceContext, backend chequebook.Backend, config *api.Config, swapEnabled, syncEnabled bool, cors string) (self *Swarm, err error) {
if bytes.Equal(common.FromHex(config.PublicKey), storage.ZeroKey) {
return nil, fmt.Errorf("empty public key")
}
@@ -84,6 +85,7 @@ func NewSwarm(ctx *node.ServiceContext, backend chequebook.Backend, config *api.
swapEnabled: swapEnabled,
backend: backend,
privateKey: config.Swap.PrivateKey(),
+ corsString: cors,
}
glog.V(logger.Debug).Infof("Setting up Swarm service components")
@@ -188,10 +190,16 @@ func (self *Swarm) Start(net *p2p.Server) error {
// start swarm http proxy server
if self.config.Port != "" {
- go httpapi.StartHttpServer(self.api, self.config.Port)
+ addr := ":" + self.config.Port
+ go httpapi.StartHttpServer(self.api, &httpapi.Server{Addr: addr, CorsString: self.corsString})
}
+
glog.V(logger.Debug).Infof("Swarm http proxy started on port: %v", self.config.Port)
+ if self.corsString != "" {
+ glog.V(logger.Debug).Infof("Swarm http proxy started with corsdomain:", self.corsString)
+ }
+
return nil
}