- Update dbis_core, cross-chain-pmm-lps, explorer-monorepo, metamask-integration, pr-workspace/chains - Omit embedded publish git dirs and empty placeholders from index Made-with: Cursor
124 lines
4.7 KiB
Bash
124 lines
4.7 KiB
Bash
#!/usr/bin/env bash
|
|
# Ensure explorer nginx proxies /token-aggregation/api/v2/ to the token-aggregation service.
|
|
# Run inside VMID 5000.
|
|
|
|
set -euo pipefail
|
|
|
|
CONFIG_FILE="${CONFIG_FILE:-/etc/nginx/sites-available/blockscout}"
|
|
TOKEN_AGG_PORT="${TOKEN_AGG_PORT:-3001}"
|
|
|
|
if [[ ! -f "$CONFIG_FILE" ]]; then
|
|
echo "Config not found: $CONFIG_FILE" >&2
|
|
exit 1
|
|
fi
|
|
|
|
python3 - "$CONFIG_FILE" "$TOKEN_AGG_PORT" <<'PY'
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
cfg = Path(sys.argv[1])
|
|
port = sys.argv[2]
|
|
text = cfg.read_text()
|
|
|
|
if "location /token-aggregation/api/v2/" in text:
|
|
print("Config already has /token-aggregation/api/v2/")
|
|
raise SystemExit(0)
|
|
|
|
old = """ # Token-aggregation API for live route-tree, quotes, and market data
|
|
location /token-aggregation/api/v1/ {
|
|
proxy_pass http://127.0.0.1:__PORT__/api/v1/;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_read_timeout 60s;
|
|
add_header Access-Control-Allow-Origin *;
|
|
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
|
|
add_header Access-Control-Allow-Headers "Content-Type";
|
|
}
|
|
""".replace("__PORT__", port)
|
|
|
|
new = """ # Token-aggregation API for live route-tree, quotes, and market data
|
|
location /token-aggregation/api/v1/ {
|
|
proxy_pass http://127.0.0.1:__PORT__/api/v1/;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_read_timeout 60s;
|
|
add_header Access-Control-Allow-Origin *;
|
|
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
|
|
add_header Access-Control-Allow-Headers "Content-Type";
|
|
}
|
|
|
|
# Token-aggregation planner-v2 API (keep under /token-aggregation to avoid colliding with Blockscout /api/v2)
|
|
location /token-aggregation/api/v2/ {
|
|
proxy_pass http://127.0.0.1:__PORT__/api/v2/;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_read_timeout 60s;
|
|
add_header Access-Control-Allow-Origin *;
|
|
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
|
|
add_header Access-Control-Allow-Headers "Content-Type";
|
|
}
|
|
""".replace("__PORT__", port)
|
|
|
|
https_old = """ # Token-aggregation API for the explorer SPA live route-tree and pool intelligence.
|
|
location /token-aggregation/api/v1/ {
|
|
proxy_pass http://127.0.0.1:__PORT__/api/v1/;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_read_timeout 60s;
|
|
add_header Access-Control-Allow-Origin *;
|
|
}
|
|
""".replace("__PORT__", port)
|
|
|
|
https_new = """ # Token-aggregation API for the explorer SPA live route-tree and pool intelligence.
|
|
location /token-aggregation/api/v1/ {
|
|
proxy_pass http://127.0.0.1:__PORT__/api/v1/;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_read_timeout 60s;
|
|
add_header Access-Control-Allow-Origin *;
|
|
}
|
|
|
|
# Token-aggregation planner-v2 API for the explorer SPA.
|
|
location /token-aggregation/api/v2/ {
|
|
proxy_pass http://127.0.0.1:__PORT__/api/v2/;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_read_timeout 60s;
|
|
add_header Access-Control-Allow-Origin *;
|
|
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
|
|
add_header Access-Control-Allow-Headers "Content-Type, Authorization";
|
|
}
|
|
""".replace("__PORT__", port)
|
|
|
|
if old not in text:
|
|
raise SystemExit("Could not locate HTTP /token-aggregation/api/v1/ block")
|
|
if https_old not in text:
|
|
raise SystemExit("Could not locate HTTPS /token-aggregation/api/v1/ block")
|
|
|
|
text = text.replace(old, new, 1)
|
|
text = text.replace(https_old, https_new, 1)
|
|
cfg.write_text(text)
|
|
print(f"Inserted /token-aggregation/api/v2/ proxy to 127.0.0.1:{port}")
|
|
PY
|
|
|
|
nginx -t
|
|
nginx -s reload
|