Freshness diagnostics API, UI trust notes, mission control/stats updates, and deploy scripts.
Made-with: Cursor
This commit is contained in:
@@ -177,6 +177,21 @@ from pathlib import Path
|
||||
import re
|
||||
path = Path('/etc/nginx/sites-available/blockscout')
|
||||
text = path.read_text()
|
||||
stats_block = ''' # Explorer stats override: keep freshness/completeness metadata on the explorer-owned backend.
|
||||
location = /api/v2/stats {
|
||||
proxy_pass http://127.0.0.1:8081/api/v2/stats;
|
||||
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";
|
||||
}
|
||||
|
||||
'''
|
||||
explorer_block = ''' # Explorer backend API (auth, features, AI, explorer-owned v1 helpers)
|
||||
location /explorer-api/v1/ {
|
||||
proxy_pass http://127.0.0.1:8081/api/v1/;
|
||||
@@ -195,6 +210,58 @@ explorer_block = ''' # Explorer backend API (auth, features, AI, explorer-own
|
||||
escaped_explorer_block = explorer_block.replace('$', '\\$')
|
||||
if escaped_explorer_block in text:
|
||||
text = text.replace(escaped_explorer_block, explorer_block)
|
||||
escaped_stats_block = stats_block.replace('$', '\\$')
|
||||
if escaped_stats_block in text:
|
||||
text = text.replace(escaped_stats_block, stats_block)
|
||||
|
||||
def dedupe_named_location_block(text: str, marker: str, next_markers: list[str]) -> str:
|
||||
first = text.find(marker)
|
||||
if first == -1:
|
||||
return text
|
||||
second = text.find(marker, first + len(marker))
|
||||
if second == -1:
|
||||
return text
|
||||
|
||||
next_positions = [text.find(candidate, second) for candidate in next_markers]
|
||||
next_positions = [pos for pos in next_positions if pos != -1]
|
||||
if not next_positions:
|
||||
return text
|
||||
|
||||
return text[:first] + text[second:min(next_positions)] + text[min(next_positions):]
|
||||
|
||||
text = dedupe_named_location_block(
|
||||
text,
|
||||
' # Explorer backend API (auth, features, AI, explorer-owned v1 helpers)\n',
|
||||
[
|
||||
' # Blockscout API endpoint - MUST come before the redirect location\n',
|
||||
' # API endpoint - MUST come before the redirect location\n',
|
||||
' # Token-aggregation API for the explorer SPA live route-tree and pool intelligence.\n',
|
||||
' # Token-aggregation API at /api/v1/ for the Snap site. Service runs on port 3001.\n',
|
||||
],
|
||||
)
|
||||
text = dedupe_named_location_block(
|
||||
text,
|
||||
' # Explorer stats override: keep freshness/completeness metadata on the explorer-owned backend.\n',
|
||||
[
|
||||
' # Explorer backend API (auth, features, AI, explorer-owned v1 helpers)\n',
|
||||
' # Blockscout API endpoint - MUST come before the redirect location\n',
|
||||
' # API endpoint - MUST come before the redirect location\n',
|
||||
' # Token-aggregation API for the explorer SPA live route-tree and pool intelligence.\n',
|
||||
' # Token-aggregation API at /api/v1/ for the Snap site. Service runs on port 3001.\n',
|
||||
],
|
||||
)
|
||||
text = dedupe_named_location_block(
|
||||
text,
|
||||
' # Enriched explorer stats come from the Go-side API on 8081.\n',
|
||||
[
|
||||
' # Explorer stats override: keep freshness/completeness metadata on the explorer-owned backend.\n',
|
||||
' # Explorer backend API (auth, features, AI, explorer-owned v1 helpers)\n',
|
||||
' # Blockscout API endpoint - MUST come before the redirect location\n',
|
||||
' # API endpoint - MUST come before the redirect location\n',
|
||||
' # Token-aggregation API for the explorer SPA live route-tree and pool intelligence.\n',
|
||||
' # Token-aggregation API at /api/v1/ for the Snap site. Service runs on port 3001.\n',
|
||||
],
|
||||
)
|
||||
|
||||
legacy_patterns = [
|
||||
r"\n\s*# Explorer AI endpoints on the explorer backend service \(HTTP\)\n\s*location /api/v1/ai/ \{.*?\n\s*\}\n",
|
||||
@@ -206,6 +273,12 @@ for pattern in legacy_patterns:
|
||||
|
||||
http_needle = ' # Blockscout API endpoint - MUST come before the redirect location\n'
|
||||
legacy_http_needle = ' # API endpoint - MUST come before the redirect location\n'
|
||||
if stats_block not in text:
|
||||
if http_needle in text:
|
||||
text = text.replace(http_needle, stats_block + http_needle, 1)
|
||||
elif legacy_http_needle in text:
|
||||
text = text.replace(legacy_http_needle, stats_block + ' # Blockscout API endpoint - MUST come before the redirect location\n', 1)
|
||||
|
||||
if explorer_block not in text:
|
||||
if http_needle in text:
|
||||
text = text.replace(http_needle, explorer_block + http_needle, 1)
|
||||
@@ -213,6 +286,8 @@ if explorer_block not in text:
|
||||
text = text.replace(legacy_http_needle, explorer_block + ' # Blockscout API endpoint - MUST come before the redirect location\n', 1)
|
||||
|
||||
https_needle = ' # Token-aggregation API for the explorer SPA live route-tree and pool intelligence.\n'
|
||||
if stats_block not in text[text.find('# HTTPS server - Blockscout Explorer'):]:
|
||||
text = text.replace(' # Token-aggregation API at /api/v1/ for the Snap site. Service runs on port 3001.\n location /api/v1/ {\n proxy_pass http://127.0.0.1:3001/api/v1/;\n proxy_http_version 1.1;\n proxy_set_header Host $host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n proxy_set_header X-Forwarded-Proto $scheme;\n proxy_read_timeout 60s;\n add_header Access-Control-Allow-Origin *;\n }\n\n', stats_block + ' # Token-aggregation API at /api/v1/ for the Snap site. Service runs on port 3001.\n location /api/v1/ {\n proxy_pass http://127.0.0.1:3001/api/v1/;\n proxy_http_version 1.1;\n proxy_set_header Host $host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n proxy_set_header X-Forwarded-Proto $scheme;\n proxy_read_timeout 60s;\n add_header Access-Control-Allow-Origin *;\n }\n\n', 1)
|
||||
if explorer_block not in text[text.find('# HTTPS server - Blockscout Explorer'):]:
|
||||
text = text.replace(' # Token-aggregation API at /api/v1/ for the Snap site. Service runs on port 3001.\n location /api/v1/ {\n proxy_pass http://127.0.0.1:3001/api/v1/;\n proxy_http_version 1.1;\n proxy_set_header Host $host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n proxy_set_header X-Forwarded-Proto $scheme;\n proxy_read_timeout 60s;\n add_header Access-Control-Allow-Origin *;\n }\n\n', explorer_block, 1)
|
||||
path.write_text(text)
|
||||
|
||||
Reference in New Issue
Block a user