Skip to content

Commit

Permalink
Track all requests from the API as the same client
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Feb 13, 2021
1 parent 4677b60 commit e0f8e6b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/api/memes.py
Expand Up @@ -108,7 +108,7 @@ async def auto(request):
return response.json({"message": f"No results matched: {text}"}, status=404)

parts = urlparse(results[0]["image_url"])
url = f"{settings.SCHEME}://{settings.SERVER_NAME}{parts.path}"
url = f"{settings.BASE_URL}{parts.path}"
if "background" in parts.query:
url += "?background=" + parse_qs(parts.query)["background"][0]
logger.info(f"Top result: {url}")
Expand Down
6 changes: 4 additions & 2 deletions app/settings.py
Expand Up @@ -7,6 +7,7 @@

PORT = int(os.environ.get("PORT", 5000))
WORKERS = int(os.environ.get("WEB_CONCURRENCY", 1))
DEBUG = bool(os.environ.get("DEBUG", False))

if "DOMAIN" in os.environ: # staging / production
SERVER_NAME = os.environ["DOMAIN"]
Expand All @@ -21,9 +22,8 @@
RELEASE_STAGE = "local"
SCHEME = "http"

DEBUG = bool(os.environ.get("DEBUG", False))
BASE_URL = f"{SCHEME}://{SERVER_NAME}"
DEPLOYED = RELEASE_STAGE != "local" and not DEBUG
BUGSNAG_API_KEY = os.getenv("BUGSNAG_API_KEY")

# Fonts

Expand Down Expand Up @@ -93,3 +93,5 @@
DEFAULT_WATERMARK = ALLOWED_WATERMARKS[0]

REMOTE_TRACKING_URL = os.getenv("REMOTE_TRACKING_URL")

BUGSNAG_API_KEY = os.getenv("BUGSNAG_API_KEY")
5 changes: 4 additions & 1 deletion app/utils/meta.py
Expand Up @@ -87,7 +87,10 @@ async def search(request, text: str) -> list[dict]:


def _get_referer(request):
return request.headers.get("referer") or request.args.get("referer")
referer = request.headers.get("referer") or request.args.get("referer")
if referer and referer.startswith(settings.BASE_URL):
referer = None
return referer


def _get_api_key(request):
Expand Down

0 comments on commit e0f8e6b

Please sign in to comment.