Skip to content

Commit cce3ec7

Browse files
authored
Merge pull request #151 from NodeFactoryIo/mpetrun5/enable-origin-and-cors
Enable origin and cors
2 parents eea5915 + b66092f commit cce3ec7

7 files changed

Lines changed: 34 additions & 7 deletions

File tree

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=0.3.0
1+
version=0.3.1

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
## [unreleased]((https://github.com/NodeFactoryIo/vedran/tree/HEAD))
44

5+
[Full Changelog](https://github.com/NodeFactoryIo/vedran/compare/v0.3.1...HEAD)
6+
7+
## [v0.3.1]((https://github.com/NodeFactoryIo/vedran/tree/v0.3.1))
8+
9+
### Added
10+
11+
### Fix
12+
- Enable CORS and set upgrader CheckOrigin to true [\#149](https://github.com/NodeFactoryIo/vedran/pull/149) ([mpetrun5](https://github.com/mpetrun5))
13+
14+
### Changed
15+
516
[Full Changelog](https://github.com/NodeFactoryIo/vedran/compare/v0.3.0...HEAD)
617
## [v0.3.0]((https://github.com/NodeFactoryIo/vedran/tree/v0.3.0))
718

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
1111
vedran:
1212
command: start --auth-secret=test-secret --log-level debug --public-ip vedran --server-port 4000 --private-key ${VEDRAN_LB_PK:-0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a} --payout-interval 1 --payout-reward ${VEDRAN_LB_REWARD_POOL:-10}
13-
image: nodefactory/vedran:v0.3.0
13+
image: nodefactory/vedran:v0.3.1
1414
ports:
1515
- "4000:4000"
1616
container_name: "vedran"

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/dgrijalva/jwt-go v3.2.0+incompatible
1111
github.com/ethereum/go-ethereum v1.9.24
1212
github.com/golang/gddo v0.0.0-20200831202555-721e228c7686
13+
github.com/gorilla/handlers v1.5.1
1314
github.com/gorilla/mux v1.8.0
1415
github.com/gorilla/websocket v1.4.1
1516
github.com/gosuri/uitable v0.0.4

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ github.com/ethereum/go-ethereum v1.9.24 h1:6AK+ORt3EMDO+FTjzXy/AQwHMbu52J2nYHIjy
8484
github.com/ethereum/go-ethereum v1.9.24/go.mod h1:JIfVb6esrqALTExdz9hRYvrP0xBDf6wCncIu1hNwHpM=
8585
github.com/fatih/color v1.3.0 h1:YehCCcyeQ6Km0D6+IapqPinWBK6y+0eB5umvZXK9WPs=
8686
github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
87+
github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
88+
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
8789
github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
8890
github.com/fsnotify/fsnotify v1.4.3-0.20170329110642-4da3e2cfbabc/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
8991
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
@@ -135,6 +137,8 @@ github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
135137
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
136138
github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
137139
github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY=
140+
github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4=
141+
github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q=
138142
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
139143
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
140144
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=

internal/controllers/ws.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
package controllers
22

33
import (
4+
"net/http"
5+
46
"github.com/NodeFactoryIo/vedran/internal/configuration"
57
"github.com/NodeFactoryIo/vedran/internal/ws"
68
"github.com/gorilla/websocket"
79
log "github.com/sirupsen/logrus"
8-
"net/http"
910
)
1011

1112
var upgrader = websocket.Upgrader{
1213
ReadBufferSize: 1024,
1314
WriteBufferSize: 1024,
15+
CheckOrigin: func(r *http.Request) bool {
16+
return true
17+
},
1418
}
1519

1620
func (c ApiController) WSHandler(w http.ResponseWriter, r *http.Request) {

internal/loadbalancer/server.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package loadbalancer
22

33
import (
44
"fmt"
5+
"net/http"
6+
"time"
7+
58
"github.com/NodeFactoryIo/vedran/internal/actions"
69
"github.com/NodeFactoryIo/vedran/internal/auth"
710
"github.com/NodeFactoryIo/vedran/internal/configuration"
@@ -13,9 +16,8 @@ import (
1316
schedulepayout "github.com/NodeFactoryIo/vedran/internal/schedule/payout"
1417
"github.com/NodeFactoryIo/vedran/internal/schedule/penalize"
1518
"github.com/asdine/storm/v3"
19+
"github.com/gorilla/handlers"
1620
log "github.com/sirupsen/logrus"
17-
"net/http"
18-
"time"
1921
)
2022

2123
func StartLoadBalancerServer(
@@ -94,9 +96,14 @@ func StartLoadBalancerServer(
9496
)
9597
r := router.CreateNewApiRouter(apiController)
9698
if props.CertFile != "" {
97-
err = http.ListenAndServeTLS(fmt.Sprintf(":%d", props.Port), props.CertFile, props.KeyFile, r)
99+
err = http.ListenAndServeTLS(
100+
fmt.Sprintf(":%d", props.Port),
101+
props.CertFile,
102+
props.KeyFile,
103+
handlers.CORS()(r),
104+
)
98105
} else {
99-
err = http.ListenAndServe(fmt.Sprintf(":%d", props.Port), r)
106+
err = http.ListenAndServe(fmt.Sprintf(":%d", props.Port), handlers.CORS()(r))
100107
}
101108
if err != nil {
102109
log.Error(err)

0 commit comments

Comments
 (0)