From d01081fd83127a531ea60134295e1ab769f8e471 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Tue, 11 Dec 2018 12:14:05 +0100 Subject: [PATCH] Allow websocket connections from all origins --- blockbook.go | 2 +- server/websocket.go | 6 ++++++ static/test-websocket.html | 12 ++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/blockbook.go b/blockbook.go index 9f918172..ffc7cd28 100644 --- a/blockbook.go +++ b/blockbook.go @@ -505,10 +505,10 @@ func onNewTxAddr(tx *bchain.Tx, desc bchain.AddressDescriptor, isOutput bool) { } func pushSynchronizationHandler(nt bchain.NotificationType) { + glog.V(1).Info("MQ: notification ", nt) if atomic.LoadInt32(&inShutdown) != 0 { return } - glog.V(1).Info("MQ: notification ", nt) if nt == bchain.NotificationNewBlock { chanSyncIndex <- struct{}{} } else if nt == bchain.NotificationNewTx { diff --git a/server/websocket.go b/server/websocket.go index cd8ae847..d4ebf745 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -76,6 +76,7 @@ func NewWebsocketServer(db *db.RocksDB, chain bchain.BlockChain, txCache *db.TxC upgrader: &websocket.Upgrader{ ReadBufferSize: 1024 * 32, WriteBufferSize: 1024 * 32, + CheckOrigin: checkOrigin, }, db: db, txCache: txCache, @@ -90,6 +91,11 @@ func NewWebsocketServer(db *db.RocksDB, chain bchain.BlockChain, txCache *db.TxC return s, nil } +// allow all origins, at least for now +func checkOrigin(r *http.Request) bool { + return true +} + // ServeHTTP sets up handler of websocket channel func (s *WebsocketServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { if r.Method != "GET" { diff --git a/static/test-websocket.html b/static/test-websocket.html index c854b1d2..8e94db61 100644 --- a/static/test-websocket.html +++ b/static/test-websocket.html @@ -136,9 +136,9 @@ } subscribeNewBlockId = subscribe(method, params, function (result) { document.getElementById('subscribeNewBlockResult').innerText += JSON.stringify(result).replace(/,/g, ", ") + "\n"; - document.getElementById('subscribeNewBlockId').innerText = subscribeNewBlockId; - document.getElementById('unsubscribeNewBlockButton').setAttribute("style", "display: inherit;"); }); + document.getElementById('subscribeNewBlockId').innerText = subscribeNewBlockId; + document.getElementById('unsubscribeNewBlockButton').setAttribute("style", "display: inherit;"); } function unsubscribeNewBlock() { @@ -166,9 +166,9 @@ } subscribeAddressesId = subscribe(method, params, function (result) { document.getElementById('subscribeAddressesResult').innerText += JSON.stringify(result).replace(/,/g, ", ") + "\n"; - document.getElementById('subscribeAddressesIds').innerText = subscribeAddressesId; - document.getElementById('unsubscribeAddressesButton').setAttribute("style", "display: inherit;"); }); + document.getElementById('subscribeAddressesIds').innerText = subscribeAddressesId; + document.getElementById('unsubscribeAddressesButton').setAttribute("style", "display: inherit;"); } function unsubscribeAddresses() { @@ -347,9 +347,9 @@
- -
+ +