api: use API_HOST env variable everywhere (#21814)

* api base url to global constant

* update api/__init__.py
old-commit-hash: 543e019f715a7e485c7402d1e145dc8e81d43611
This commit is contained in:
Dean Lee
2021-08-03 19:49:49 +08:00
committed by GitHub
parent 51698f04bc
commit ceb40d8384
7 changed files with 12 additions and 10 deletions

View File

@@ -1,9 +1,12 @@
import jwt
import os
import requests
from datetime import datetime, timedelta
from common.basedir import PERSIST
from selfdrive.version import version
API_HOST = os.getenv('API_HOST', 'https://api.commadotai.com')
class Api():
def __init__(self, dongle_id):
self.dongle_id = dongle_id
@@ -34,12 +37,10 @@ class Api():
def api_get(endpoint, method='GET', timeout=None, access_token=None, **params):
backend = "https://api.commadotai.com/"
headers = {}
if access_token is not None:
headers['Authorization'] = "JWT "+access_token
headers['User-Agent'] = "openpilot-" + version
return requests.request(method, backend+endpoint, timeout=timeout, headers=headers, params=params)
return requests.request(method, API_HOST+endpoint, timeout=timeout, headers=headers, params=params)