From 989013c02ad1b20b00e5e6ab4bd0e70c82a75bc7 Mon Sep 17 00:00:00 2001 From: c0ban-project <39722780+c0ban-project@users.noreply.github.com> Date: Wed, 23 Jan 2019 16:02:18 +0900 Subject: [PATCH 1/3] Add url for regtest mode --- docker/nginx/counterwallet.conf.template | 44 +++++++++++++++++++++++- docker/start.sh | 6 +++- src/js/components/balances_assets.js | 6 ++-- src/js/components/leaderboard.js | 3 +- src/js/counterwallet.js | 2 +- src/js/util.js | 6 ++-- 6 files changed, 59 insertions(+), 8 deletions(-) diff --git a/docker/nginx/counterwallet.conf.template b/docker/nginx/counterwallet.conf.template index 908923db9..ccd4bda72 100644 --- a/docker/nginx/counterwallet.conf.template +++ b/docker/nginx/counterwallet.conf.template @@ -10,6 +10,10 @@ upstream counterblock_t_api_server { server ${COUNTERBLOCK_HOST_TESTNET}:${COUNTERBLOCK_PORT_TESTNET}; keepalive 30; } +upstream counterblock_r_api_server { + server ${COUNTERBLOCK_HOST_REGTEST}:${COUNTERBLOCK_PORT_REGTEST}; + keepalive 30; +} #Content Security Policy (CSP) header add_header Content-Security-Policy "default-src 'self'; script-src 'self' https://ssl.google-analytics.com https://query.yahooapis.com; img-src 'self' data: https://ssl.google-analytics.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://themes.googleusercontent.com https://fonts.gstatic.com; frame-src 'none'; object-src 'self'; connect-src 'self' wss://$host wss://*.counterwallet.io https://*.counterwallet.io https://api.rollbar.com https://bitcoinfees.earn.com https://apiv2.bitcoinaverage.com https://min-api.cryptocompare.com; report-uri /_report_csp/;"; @@ -81,6 +85,11 @@ server { expires 1h; alias /counterblock_data/asset_img.testnet/; } + location /_r_asset_img/ { + access_log off; + expires 1h; + alias /counterblock_data/asset_img.regtest/; + } location /src { #For dev/testing (uses unminified resources) open_file_cache off; @@ -165,7 +174,40 @@ server { include /etc/nginx/sites-enabled/counterblock_socketio.inc; proxy_pass http://${COUNTERBLOCK_HOST_TESTNET}:${COUNTERBLOCK_PORT_TESTNET_CHAT}/socket.io; } - + + ##### + # REGTEST + # PROXY TO COUNTERBLOCK API REQUESTS (WSGI) - try to hit the cache in redis first + location ^~ /_r_api + { + #reject everything except GET, POST and OPTIONS + limit_except GET POST OPTIONS { + deny all; + } + + include /etc/nginx/sites-enabled/counterblock_api_cache.inc; + set $redis_db "2"; + + # Send to app server if Redis could not answer the request + error_page 404 405 550 = @r_wsgi_api; + } + # PROXY TO COUNTERBLOCK API BACKEND (WSGI) + location @r_wsgi_api { + include /etc/nginx/sites-enabled/counterblock_api.inc; + rewrite ^/_r_api/?$ /api/? break; + proxy_pass http://counterblock_r_api_server; + } + # PROXY TO COUNTERBLOCK FEED BACKEND (socket.io) + location ^~ /_r_feed { + include /etc/nginx/sites-enabled/counterblock_socketio.inc; + proxy_pass http://${COUNTERBLOCK_HOST_REGTEST}:${COUNTERBLOCK_PORT_REGTEST_FEED}/socket.io; + } + # PROXY TO COUNTERBLOCK CHAT BACKEND (socket.io) + location ^~ /_r_chat { + include /etc/nginx/sites-enabled/counterblock_socketio.inc; + proxy_pass http://${COUNTERBLOCK_HOST_REGTEST}:${COUNTERBLOCK_PORT_REGTEST_CHAT}/socket.io; + } + ##### # CSP REPORTING (mainnet and testnet) location ^~ /_report_csp/ { diff --git a/docker/start.sh b/docker/start.sh index 8ac7f9b95..b823c2db3 100644 --- a/docker/start.sh +++ b/docker/start.sh @@ -24,14 +24,18 @@ export REDIS_PORT=${REDIS_PORT:=6379} export REDIS_DB=${REDIS_DB:=0} export COUNTERBLOCK_HOST_MAINNET=${COUNTERBLOCK_HOST_MAINNET:="counterblock"} export COUNTERBLOCK_HOST_TESTNET=${COUNTERBLOCK_HOST_TESTNET:="counterblock-testnet"} +export COUNTERBLOCK_HOST_REGTEST=${COUNTERBLOCK_HOST_REGTEST:="counterblock-regtest"} export COUNTERBLOCK_PORT_MAINNET=${COUNTERBLOCK_PORT_MAINNET:=4100} export COUNTERBLOCK_PORT_TESTNET=${COUNTERBLOCK_PORT_TESTNET:=14100} +export COUNTERBLOCK_PORT_REGTEST=${COUNTERBLOCK_PORT_REGTEST:=24100} export COUNTERBLOCK_PORT_MAINNET_FEED=${COUNTERBLOCK_PORT_MAINNET_FEED:=4101} export COUNTERBLOCK_PORT_TESTNET_FEED=${COUNTERBLOCK_PORT_TESTNET_FEED:=14101} +export COUNTERBLOCK_PORT_REGTEST_FEED=${COUNTERBLOCK_PORT_REGTEST_FEED:=24101} export COUNTERBLOCK_PORT_MAINNET_CHAT=${COUNTERBLOCK_PORT_MAINNET_CHAT:=4102} export COUNTERBLOCK_PORT_TESTNET_CHAT=${COUNTERBLOCK_PORT_TESTNET_CHAT:=14102} +export COUNTERBLOCK_PORT_REGTEST_CHAT=${COUNTERBLOCK_PORT_REGTEST_CHAT:=24102} -VARS='$REDIS_HOST:$REDIS_PORT:$REDIS_DB:$COUNTERBLOCK_HOST_MAINNET:$COUNTERBLOCK_HOST_TESTNET:$COUNTERBLOCK_PORT_MAINNET:$COUNTERBLOCK_PORT_TESTNET:$COUNTERBLOCK_PORT_MAINNET_FEED:$COUNTERBLOCK_PORT_TESTNET_FEED:$COUNTERBLOCK_PORT_MAINNET_CHAT:$COUNTERBLOCK_PORT_TESTNET_CHAT' +VARS='$REDIS_HOST:$REDIS_PORT:$REDIS_DB:$COUNTERBLOCK_HOST_MAINNET:$COUNTERBLOCK_HOST_TESTNET:$COUNTERBLOCK_HOST_REGTEST:$COUNTERBLOCK_PORT_MAINNET:$COUNTERBLOCK_PORT_TESTNET:$COUNTERBLOCK_PORT_REGTEST:$COUNTERBLOCK_PORT_MAINNET_FEED:$COUNTERBLOCK_PORT_TESTNET_FEED:$COUNTERBLOCK_PORT_REGTEST_FEED:$COUNTERBLOCK_PORT_MAINNET_CHAT:$COUNTERBLOCK_PORT_TESTNET_CHAT:$COUNTERBLOCK_PORT_REGTEST_CHAT' envsubst "$VARS" < /counterwallet/docker/nginx/counterwallet.conf.template > /etc/nginx/sites-enabled/counterwallet.conf # Launch utilizing the SIGTERM/SIGINT propagation pattern from diff --git a/src/js/components/balances_assets.js b/src/js/components/balances_assets.js index f0cc049d0..078852ea5 100644 --- a/src/js/components/balances_assets.js +++ b/src/js/components/balances_assets.js @@ -919,8 +919,10 @@ function ShowAssetInfoModalViewModel() { if (!ext_info) return; //asset has no extended info - if (ext_info['image']) - self.extImageURL((USE_TESTNET ? '/_t_asset_img/' : '/_asset_img/') + assetObj.ASSET + '.png'); + if (ext_info['image']) { + var prefix = USE_TESTNET ? '_t' : (USE_REGTEST ? '_r' : ''); + self.extImageURL('/' + prefix + '_asset_img/' + assetObj.ASSET + '.png'); + } self.extWebsite(ext_info['website']); self.extDescription(ext_info['description']); diff --git a/src/js/components/leaderboard.js b/src/js/components/leaderboard.js index ab8531e87..295ace460 100644 --- a/src/js/components/leaderboard.js +++ b/src/js/components/leaderboard.js @@ -222,7 +222,8 @@ AssetLeaderboardViewModel.formulateExtendedAssetInfo = function(asset, hasImage, var website = asset === KEY_ASSET.XCP ? KEY_ASSET_WEBSITE.XCP : KEY_ASSET_WEBSITE.BTC; dispAsset += '' + asset + ''; } else if (hasImage) { - dispAsset = ' '; + var prefix = USE_TESTNET ? '_t' : (USE_REGTEST ? '_r' : ''); + dispAsset = ' '; //dispAsset += website ? ('' + asset + '') : asset; dispAsset += asset; //keep it simple for now for avoid XSS } diff --git a/src/js/counterwallet.js b/src/js/counterwallet.js index 0d3624895..5b81160ee 100644 --- a/src/js/counterwallet.js +++ b/src/js/counterwallet.js @@ -66,7 +66,7 @@ function produceCWServerList() { if (USE_TESTNET) { return element + '/_t_api'; } else if (USE_REGTEST) { - return element + '/'; + return element + '/_r_api'; } else { return element + '/_api'; } diff --git a/src/js/util.js b/src/js/util.js index be0e1ebda..e3509e1cf 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -15,14 +15,16 @@ function cleanHtmlPrice(price) { function feedImageUrl(image_name) { var url = cwBaseURLs()[0]; - url += USE_TESTNET ? '/_t_feed_img/' : '/_feed_img/'; + var prefix = USE_TESTNET ? "_t" : ( USE_REGTEST ? "_r" : ""); + url += '/' + prefix + '_feed_img/'; url += image_name + '.png'; return url; } function assetImageUrl(image_name) { var url = cwBaseURLs()[0]; - url += USE_TESTNET ? '/_t_asset_img/' : '/_asset_img/'; + var prefix = USE_TESTNET ? "_t" : ( USE_REGTEST ? "_r" : ""); + url += '/' + prefix + '_asset_img/'; url += image_name + '.png'; return url; } From 6774071424255d754fc59e793c1df03be979c0b4 Mon Sep 17 00:00:00 2001 From: c0ban-project <39722780+c0ban-project@users.noreply.github.com> Date: Wed, 23 Jan 2019 16:05:27 +0900 Subject: [PATCH 2/3] Corresponding to "regtest mode" in more detail --- src/css/misc.css | 6 +++--- src/index.html | 2 +- src/js/components/balances.js | 3 ++- src/js/components/history.js | 2 +- src/js/components/logon.js | 13 +++++++------ src/js/components/misc.js | 1 + src/js/components/wallet.js | 4 ++-- src/js/counterwallet.js | 6 +++--- src/js/pages.init.js | 1 + src/js/util.knockout.js | 12 ++++++------ src/locales/en/translation.json | 2 ++ 11 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/css/misc.css b/src/css/misc.css index c029b5e20..7ae2e9161 100644 --- a/src/css/misc.css +++ b/src/css/misc.css @@ -74,7 +74,7 @@ span.modeIndicator { } -#noticeTestnet { +#noticeTestnet, #noticeRegtest { font-size: 26px; font-weight: bolder; color: red; @@ -91,7 +91,7 @@ span.modeIndicator { } @media only screen and (max-width : 860px) { - #noticeTestnet { + #noticeTestnet, #noticeRegtest { font-size:13px; min-width: 116px; margin-left: -58px; @@ -99,7 +99,7 @@ span.modeIndicator { } @media only screen and (max-width : 500px) { - #noticeTestnet { + #noticeTestnet, #noticeRegtest { display:none; } } diff --git a/src/index.html b/src/index.html index 1deccf108..b99433b23 100644 --- a/src/index.html +++ b/src/index.html @@ -101,7 +101,7 @@
- REGTEST +