From 0319465594bfad4a9f529d8047997bfbb18e9f7f Mon Sep 17 00:00:00 2001 From: wiz Date: Tue, 12 Jan 2021 09:35:53 +0900 Subject: [PATCH] Mempool v2.0.0 (#1933) --- .../nginx/sites-available/mempool_ssl.conf | 23 +--- .../nginx/sites-available/mempool_tor.conf | 25 +--- .../sites-available/mempool_tor_ssl.conf | 22 +--- .../assets/nginx/snippets/mempool-http.conf | 49 ++++++++ home.admin/assets/nginx/snippets/mempool.conf | 62 +++++++++ home.admin/config.scripts/bonus.mempool.sh | 119 +++++++++--------- 6 files changed, 172 insertions(+), 128 deletions(-) create mode 100644 home.admin/assets/nginx/snippets/mempool-http.conf create mode 100644 home.admin/assets/nginx/snippets/mempool.conf diff --git a/home.admin/assets/nginx/sites-available/mempool_ssl.conf b/home.admin/assets/nginx/sites-available/mempool_ssl.conf index 6cb82ce27..d144a4f43 100644 --- a/home.admin/assets/nginx/sites-available/mempool_ssl.conf +++ b/home.admin/assets/nginx/sites-available/mempool_ssl.conf @@ -1,5 +1,6 @@ ## mempool_ssl.conf +include /etc/nginx/snippets/mempool-http.conf; server { listen 4081 ssl; @@ -8,25 +9,5 @@ server { include /etc/nginx/snippets/ssl-params.conf; include /etc/nginx/snippets/ssl-certificate-app-data.conf; - - access_log /var/log/nginx/access_thub.log; - error_log /var/log/nginx/error_thub.log; - - index index.html; - root /var/www/mempool; - - location / { - try_files $uri $uri/ /index.html =404; - } - - location /api { - proxy_pass http://127.0.0.1:8999/api; - } - - location /ws { - proxy_pass http://127.0.0.1:8999/; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "Upgrade"; - } + include /etc/nginx/snippets/mempool.conf; } diff --git a/home.admin/assets/nginx/sites-available/mempool_tor.conf b/home.admin/assets/nginx/sites-available/mempool_tor.conf index c22eff2ea..fbdc4f166 100644 --- a/home.admin/assets/nginx/sites-available/mempool_tor.conf +++ b/home.admin/assets/nginx/sites-available/mempool_tor.conf @@ -6,27 +6,6 @@ server { server_name _; include /etc/nginx/snippets/ssl-params.conf; - include /etc/nginx/snippets/ssl-certificate-app-data-tor.conf; - - access_log /var/log/nginx/access_thub.log; - error_log /var/log/nginx/error_thub.log; - - index index.html; - root /var/www/mempool; - - location / { - try_files $uri $uri/ /index.html =404; - } - - location /api { - proxy_pass http://127.0.0.1:8999/api; - } - - location /ws { - proxy_pass http://127.0.0.1:8999/; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "Upgrade"; - } - + include /etc/nginx/snippets/ssl-certificate-app-data.conf; + include /etc/nginx/snippets/mempool.conf; } diff --git a/home.admin/assets/nginx/sites-available/mempool_tor_ssl.conf b/home.admin/assets/nginx/sites-available/mempool_tor_ssl.conf index 7e4930781..39aae9556 100644 --- a/home.admin/assets/nginx/sites-available/mempool_tor_ssl.conf +++ b/home.admin/assets/nginx/sites-available/mempool_tor_ssl.conf @@ -7,25 +7,5 @@ server { include /etc/nginx/snippets/ssl-params.conf; include /etc/nginx/snippets/ssl-certificate-app-data-tor.conf; - - access_log /var/log/nginx/access_thub.log; - error_log /var/log/nginx/error_thub.log; - - index index.html; - root /var/www/mempool; - - location / { - try_files $uri $uri/ /index.html =404; - } - - location /api { - proxy_pass http://127.0.0.1:8999/api; - } - - location /ws { - proxy_pass http://127.0.0.1:8999/; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "Upgrade"; - } + include /etc/nginx/snippets/mempool.conf; } diff --git a/home.admin/assets/nginx/snippets/mempool-http.conf b/home.admin/assets/nginx/snippets/mempool-http.conf new file mode 100644 index 000000000..c9e724ada --- /dev/null +++ b/home.admin/assets/nginx/snippets/mempool-http.conf @@ -0,0 +1,49 @@ + proxy_read_timeout 300; + proxy_connect_timeout 300; + proxy_send_timeout 300; + + map $http_accept_language $header_lang { + default en-US; + ~*^en-US en-US; + ~*^en en-US; + ~*^ar ar; + ~*^cs cs; + ~*^de de; + ~*^es es; + ~*^fa fa; + ~*^fr fr; + ~*^ja ja; + ~*^ka ka; + ~*^nl nl; + ~*^nn nn; + ~*^pt pt; + ~*^sl sl; + ~*^sv sv; + ~*^tr tr; + ~*^uk uk; + ~*^vi vi; + ~*^zh zh; + } + + map $cookie_lang $lang { + default $header_lang; + ~*^en-US en-US; + ~*^en en-US; + ~*^ar ar; + ~*^cs cs; + ~*^de de; + ~*^es es; + ~*^fa fa; + ~*^fr fr; + ~*^ja ja; + ~*^ka ka; + ~*^nl nl; + ~*^nn nn; + ~*^pt pt; + ~*^sl sl; + ~*^sv sv; + ~*^tr tr; + ~*^uk uk; + ~*^vi vi; + ~*^zh zh; + } diff --git a/home.admin/assets/nginx/snippets/mempool.conf b/home.admin/assets/nginx/snippets/mempool.conf new file mode 100644 index 000000000..6da53dfd2 --- /dev/null +++ b/home.admin/assets/nginx/snippets/mempool.conf @@ -0,0 +1,62 @@ + access_log /var/log/nginx/access_mempool.log; + error_log /var/log/nginx/error_mempool.log; + + root /var/www/mempool/browser; + + index index.html; + + # fallback for all URLs i.e. /address/foo /tx/foo /block/000 + location / { + try_files /$lang/$uri /$lang/$uri/ $uri $uri/ /en-US/$uri @index-redirect; + } + location @index-redirect { + add_header vary accept-language; + rewrite (.*) /$lang/index.html; + } + + # location block using regex are matched in order + + # used to rewrite resources from // to /en-US/ + location ~ ^/(ar|bg|bs|ca|cs|da|de|et|el|es|eo|eu|fa|fr|gl|ko|hr|id|it|he|ka|lv|lt|hu|mk|ms|nl|ja|ka|no|nb|nn|pl|pt|pt-BR|ro|ru|sk|sl|sr|sh|fi|sv|th|tr|uk|vi|zh)/resources/ { + rewrite ^/[a-zA-Z-]*/resources/(.*) /en-US/resources/$1; + } + # used for cookie override + location ~ ^/(ar|bg|bs|ca|cs|da|de|et|el|es|eo|eu|fa|fr|gl|ko|hr|id|it|he|ka|lv|lt|hu|mk|ms|nl|ja|ka|no|nb|nn|pl|pt|pt-BR|ro|ru|sk|sl|sr|sh|fi|sv|th|tr|uk|vi|zh)/ { + try_files $uri $uri/ /$1/index.html =404; + } + + # static API docs + location = /api { + try_files $uri $uri/ /en-US/index.html =404; + } + location = /api/ { + try_files $uri $uri/ /en-US/index.html =404; + } + + # mainnet API + location /api/v1/donations { + proxy_pass https://mempool.space; + } + location /api/v1/donations/images { + proxy_pass https://mempool.space; + } + location /api/v1/ws { + proxy_pass http://127.0.0.1:8999/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + } + location /api/v1 { + proxy_pass http://127.0.0.1:8999/api/v1; + } + location /api/ { + proxy_pass http://127.0.0.1:8999/api/v1/; + } + + # mainnet API + location /ws { + proxy_pass http://127.0.0.1:8999/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + } diff --git a/home.admin/config.scripts/bonus.mempool.sh b/home.admin/config.scripts/bonus.mempool.sh index 752a79eb6..c576c9844 100755 --- a/home.admin/config.scripts/bonus.mempool.sh +++ b/home.admin/config.scripts/bonus.mempool.sh @@ -102,8 +102,6 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then # install nodeJS /home/admin/config.scripts/bonus.nodejs.sh on - /home/admin/config.scripts/bonus.typescript.sh on - /home/admin/config.scripts/bonus.angular_cli.sh on # make sure that txindex of blockchain is switched on /home/admin/config.scripts/network.txindex.sh on @@ -118,7 +116,7 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then cd /home/mempool sudo -u mempool git clone https://github.com/mempool/mempool.git cd mempool - sudo -u mempool git reset --hard v1.0.1 + sudo -u mempool git reset --hard v2.0.0 # modify an #echo "# try to suppress question on statistics report .." @@ -133,21 +131,30 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then echo "# npm install for mempool explorer (frontend)" cd frontend - sudo -u mempool bash -c "echo 'NG_CLI_ANALYTICS=ci' >> /home/mempool/.bashrc" - sudo -u mempool ng analytics off - yes | sudo -u mempool npm install - sudo -u mempool npm run build + sudo -u mempool NG_CLI_ANALYTICS=false npm install + if ! [ $? -eq 0 ]; then + echo "FAIL - npm install did not run correctly, aborting" + exit 1 + fi + sudo -u mempool NG_CLI_ANALYTICS=false npm run build + if ! [ $? -eq 0 ]; then + echo "FAIL - npm run build did not run correctly, aborting" + exit 1 + fi echo "# npm install for mempool explorer (backend)" cd ../backend/ - yes | sudo -u mempool npm install - sudo -u mempool npm run build - sudo -u mempool touch cache.json + sudo -u mempool NG_CLI_ANALYTICS=false npm install if ! [ $? -eq 0 ]; then echo "FAIL - npm install did not run correctly, aborting" exit 1 fi + sudo -u mempool NG_CLI_ANALYTICS=false npm run build + if ! [ $? -eq 0 ]; then + echo "FAIL - npm run build did not run correctly, aborting" + exit 1 + fi # prepare .env file echo "# getting RPC credentials from the ${network}.conf" @@ -159,54 +166,40 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then sudo chmod 600 /home/admin/mempool-config.json || exit 1 cat > /home/admin/mempool-config.json < /home/admin/proxy.conf.json <