#636 — Domain Detection Middleware

Repo: Twill-AI/facade State: closed | Status: done Assignee: meliascosta

Created: 2025-10-08 · Updated: 2025-10-22

Description

Create FastAPI middleware to detect partner from incoming request hostname and inject whitelabel configuration into request state for use by downstream handlers. Ensure middleware runs before authentication.

AC:

  • Middleware extracts hostname from request.headers.get('host')

  • Queries partner_domain table for matching verified domain

  • Loads partner_whitelabel_config if partner found

  • Injects request.state.partner_id and request.state.whitelabel_config

  • Handles missing/invalid domains gracefully (Falls back to my.twillai.com, default Twill branding)

  • Middleware registered in app/main.py before route handlers

  • Unit tests cover domain matching logic

Notes

Add implementation notes, blockers, and context here

Add wikilinks to related people, meetings, or other tickets