From fe54f4eca1d5be84155809a02dd6b6136996fbfe Mon Sep 17 00:00:00 2001 From: Ryan Westfall Date: Sun, 30 Aug 2026 19:25:03 -0500 Subject: [PATCH] Point SHORTENER_BASE_URL at piha.lc / beta.piha.li instead of a separate API host. Closes #11. --- .env.example | 4 ++-- .env.prod.example | 6 +++--- README.md | 8 ++++---- site/messaging/README.md | 2 +- site/messaging/shortener.py | 4 ++-- site/messaging/tests.py | 6 +++--- site/monica_site/settings/base.py | 6 +++--- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.env.example b/.env.example index 62f1e86..90c0745 100644 --- a/.env.example +++ b/.env.example @@ -79,8 +79,8 @@ SOCIAL_TOKEN_ENCRYPTION_KEY= OLLAMA_BASE_URL=http://10.0.0.128:11434 OLLAMA_MODEL=llama3.2 -# URL shortener (piha.li). Empty locally = long UTM URLs in campaigns. -# Call the API host, never https://piha.li (that host only 302s). +# URL shortener (piha.lc). Empty locally = long UTM URLs in campaigns. +# Call the short host: POST /api/links/ (Bearer) and recipients GET /. SHORTENER_BASE_URL= SHORTENER_API_TOKEN= # Local shortener compose: diff --git a/.env.prod.example b/.env.prod.example index 8fcb041..688f35b 100644 --- a/.env.prod.example +++ b/.env.prod.example @@ -88,10 +88,10 @@ OLLAMA_MODEL=llama3.2 OLLAMA_TIMEOUT_SECONDS=120 # URL shortener — mint short links for campaign SMS / email / postcard QR. -# POST /api/links/ on the API host. Recipients hit https://piha.li/. +# POST /api/links/ on the same host phones hit. Recipients use https://piha.lc/. # Token must match SHORTENER_API_TOKENS on url_shortening_service (name:secret). # Generate: python -c "import secrets; print(secrets.token_urlsafe(32))" -SHORTENER_BASE_URL=https://shortener.aimloperations.com +SHORTENER_BASE_URL=https://piha.lc SHORTENER_API_TOKEN=monica:replace-me # Nominatim address suggest (server-side proxy only; not called from browser) @@ -130,5 +130,5 @@ GUNICORN_BIND=0.0.0.0:8000 # OLLAMA_BASE_URL=http://10.0.0.128:11434 # NOMINATIM_BASE_URL=http://10.0.0.128:8089 # NOMINATIM_COUNTRY_CODES=us -# SHORTENER_BASE_URL=https://shortener-beta.aimloperations.com +# SHORTENER_BASE_URL=https://beta.piha.li # SHORTENER_API_TOKEN=monica:replace-with-a-different-token diff --git a/README.md b/README.md index b1a2527..1573c86 100644 --- a/README.md +++ b/README.md @@ -78,12 +78,12 @@ Campaign UTM short links (piha.li) need **both** sides: | File | Vars | |------|------| -| `monica_site_prod.env` | `SHORTENER_BASE_URL=https://shortener.aimloperations.com` · `SHORTENER_API_TOKEN=monica:` | -| `monica_site_beta.env` | `SHORTENER_BASE_URL=https://shortener-beta.aimloperations.com` · distinct `SHORTENER_API_TOKEN` | -| `url_shortening_service_prod.env` | `SHORTENER_API_TOKENS=monica:` · `SHORT_ALLOWED_HOSTS` includes `mkdrealtor.com` · `PUBLIC_SHORT_URL=https://piha.li` | +| `monica_site_prod.env` | `SHORTENER_BASE_URL=https://piha.lc` · `SHORTENER_API_TOKEN=monica:` | +| `monica_site_beta.env` | `SHORTENER_BASE_URL=https://beta.piha.li` · distinct `SHORTENER_API_TOKEN` | +| `url_shortening_service_prod.env` | `SHORTENER_API_TOKENS=monica:` · `SHORT_ALLOWED_HOSTS` includes `mkdrealtor.com` · `PUBLIC_SHORT_URL=https://piha.lc` | | `url_shortening_service_beta.env` | matching beta token · `PUBLIC_SHORT_URL=https://beta.piha.li` | -Generate the secret with `python -c "import secrets; print(secrets.token_urlsafe(32))"`. Do not put it in git. Call the API host, never `piha.li`, to mint links. +Generate the secret with `python -c "import secrets; print(secrets.token_urlsafe(32))"`. Do not put it in git. Mint and redirects share the short host; Bearer is required on `/api/`. ## Deploy diff --git a/site/messaging/README.md b/site/messaging/README.md index 1d8c657..f21506a 100644 --- a/site/messaging/README.md +++ b/site/messaging/README.md @@ -50,7 +50,7 @@ long HTTPS URL to `url_shortening_service` (`POST /api/links/`, Bearer `monica:`) and puts `short_url` (`https://piha.li/`) in SMS, email hrefs, and postcard QR codes. Empty env → long UTM URL (local default). -Mint against the **API host**, not `piha.li`. See `.env.example` / `.env.prod.example`. +Mint against the short host (`https://piha.lc` / `https://beta.piha.li`). See `.env.example` / `.env.prod.example`. SMS correlation uses `message_id` (SMS id), then `destination_number` phone fallback. Do **not** treat webhook `id` as the SMS id. diff --git a/site/messaging/shortener.py b/site/messaging/shortener.py index 023e626..3615f63 100644 --- a/site/messaging/shortener.py +++ b/site/messaging/shortener.py @@ -1,6 +1,6 @@ -"""Server-to-server client for url_shortening_service (piha.li). +"""Server-to-server client for url_shortening_service (piha.lc). -Call the API host (`SHORTENER_BASE_URL`), never the public short domain. +Call SHORTENER_BASE_URL (https://piha.lc / https://beta.piha.li). Auth: Authorization: Bearer (name:secret). """ diff --git a/site/messaging/tests.py b/site/messaging/tests.py index 72e6078..538c38e 100644 --- a/site/messaging/tests.py +++ b/site/messaging/tests.py @@ -1598,7 +1598,7 @@ class CampaignUtmLinkTests(TestCase): } with self.settings( PUBLIC_SITE_URL="https://mkdrealtor.com", - SHORTENER_BASE_URL="https://shortener.aimloperations.com", + SHORTENER_BASE_URL="https://piha.lc", SHORTENER_API_TOKEN="monica:test-token", ): with patch( @@ -1630,7 +1630,7 @@ class CampaignUtmLinkTests(TestCase): mock.text = '{"detail":"Unauthorized"}' with self.settings( PUBLIC_SITE_URL="https://mkdrealtor.com", - SHORTENER_BASE_URL="https://shortener.aimloperations.com", + SHORTENER_BASE_URL="https://piha.lc", SHORTENER_API_TOKEN="monica:bad", ): with patch("messaging.shortener.requests.post", return_value=mock): @@ -1687,7 +1687,7 @@ class CampaignUtmLinkTests(TestCase): url = reverse("messaging:campaign_short_link") with self.settings( PUBLIC_SITE_URL="https://mkdrealtor.com", - SHORTENER_BASE_URL="https://shortener.aimloperations.com", + SHORTENER_BASE_URL="https://piha.lc", SHORTENER_API_TOKEN="monica:test-token", ): with patch("messaging.shortener.requests.post", return_value=mock): diff --git a/site/monica_site/settings/base.py b/site/monica_site/settings/base.py index 55bba95..cb27ac2 100644 --- a/site/monica_site/settings/base.py +++ b/site/monica_site/settings/base.py @@ -332,9 +332,9 @@ NOMINATIM_USER_AGENT = env( ) NOMINATIM_API_KEY = env("NOMINATIM_API_KEY", "") -# --- URL shortener (piha.li) --- -# Call the API host, never the public short domain. Empty = skip minting -# (composer falls back to the long UTM URL). Token format: name:secret. +# --- URL shortener (piha.lc) --- +# Same host as SMS links. Empty = skip minting (composer falls back to the +# long UTM URL). Token format: name:secret. SHORTENER_BASE_URL = env("SHORTENER_BASE_URL", "") SHORTENER_API_TOKEN = env("SHORTENER_API_TOKEN", "") SHORTENER_TIMEOUT_SECONDS = int(env("SHORTENER_TIMEOUT_SECONDS", "10") or "10")