feat: support configured production API endpoint
This commit is contained in:
+17
-8
@@ -41,9 +41,17 @@ def _cached_detect(token):
|
||||
if cache is None:
|
||||
g._detected_endpoint = cache = {}
|
||||
if token not in cache:
|
||||
endpoint = current_app.config["NUBES_API_ENDPOINT"]
|
||||
if endpoint in STANDS:
|
||||
endpoint = detect_endpoint(token) or endpoint
|
||||
endpoint = current_app.config["NUBES_API_ENDPOINT"].rstrip("/")
|
||||
endpoints = [url.rstrip("/") for url in STANDS]
|
||||
for configured_endpoint in (
|
||||
current_app.config.get("NUBES_API_PROD_ENDPOINT", ""),
|
||||
endpoint,
|
||||
):
|
||||
configured_endpoint = configured_endpoint.rstrip("/")
|
||||
if configured_endpoint and configured_endpoint not in endpoints:
|
||||
endpoints.append(configured_endpoint)
|
||||
if endpoint in endpoints:
|
||||
endpoint = detect_endpoint(token, endpoints=endpoints) or endpoint
|
||||
cache[token] = endpoint
|
||||
return cache[token]
|
||||
|
||||
@@ -137,11 +145,12 @@ def get_stand():
|
||||
return f"polygon_{get_polygon_stand()}"
|
||||
|
||||
token = get_token()
|
||||
endpoint = current_app.config["NUBES_API_ENDPOINT"]
|
||||
if endpoint not in STANDS:
|
||||
s = stand_name(endpoint)
|
||||
return s if s != "?" else "mock"
|
||||
return stand_name(_cached_detect(token))
|
||||
endpoint = _cached_detect(token).rstrip("/")
|
||||
prod_endpoint = current_app.config.get("NUBES_API_PROD_ENDPOINT", "").rstrip("/")
|
||||
if prod_endpoint and endpoint == prod_endpoint:
|
||||
return "prod"
|
||||
s = stand_name(endpoint)
|
||||
return s if s != "?" else "mock"
|
||||
|
||||
|
||||
def get_token_info():
|
||||
|
||||
Reference in New Issue
Block a user