Support multiple domains per inbox#49
Open
PierreFouquet wants to merge 1 commit into
Open
Conversation
A single instance can already serve multiple domains by setting DOMAINS to a comma-separated list: the /api/v1/config endpoint splits it, and the New Mailbox dialog renders a domain picker when more than one is configured. This was undocumented, so users assumed it was unsupported (issue cloudflare#8). Make it a documented, first-class feature and add a matching backend guard: - Add a parseDomains() helper and reuse it in /api/v1/config. - Reject mailbox creation on domains outside the configured DOMAINS, mirroring the front-end picker. Explicit EMAIL_ADDRESSES entries bypass the check, so the auto-create flow (which may span domains) is unaffected. No DOMAINS configured means no restriction, preserving existing behavior. - Document multi-domain setup in the README ("Using multiple domains"), wrangler.jsonc, and the deploy-time DOMAINS binding description. Closes cloudflare#8 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #8 ("Connect Multiple domain in 1 worker?").
While investigating, I found that a single instance can already serve multiple domains — it was just undocumented, which is why it was assumed unsupported:
GET /api/v1/configalready splits theDOMAINSvar on commas (workers/index.ts).Selectwhen more than one domain is configured (app/routes/home.tsx).validateSender) and receiving (receiveEmail) are domain-agnostic, andEMAIL_ADDRESSEScan already span domains.This PR makes multi-domain a documented, first-class feature and adds a matching backend guard.
Changes
workers/index.ts— add aparseDomains()helper (reused by/api/v1/config), and reject mailbox creation on domains outside the configuredDOMAINS, mirroring the front-end picker. ExplicitEMAIL_ADDRESSESentries bypass the check (they are the authoritative allow-list and may legitimately span domains), and an emptyDOMAINSimposes no restriction — so existing behavior is preserved.README.md— new "Using multiple domains" section; clarified the singular "your domain" wording.wrangler.jsonc— comments documenting thatDOMAINSaccepts a comma-separated list and thatEMAIL_ADDRESSESmay span domains.package.json— expanded the deploy-timeDOMAINSbinding description.No change to send/receive behavior.
How to use
Set
DOMAINSto a comma-separated list and add a catch-all Email Routing rule (and verified sending) per domain:Testing
Verified locally with a multi-domain config (
DOMAINS="example.com,another.com") injected via a local-only Wrangler config (per the approach in #44), runningnpm run dev:GET /api/v1/config{"domains":["example.com","another.com"],"emailAddresses":[]}✅hello@example.com(1st domain)201✅hi@another.com(2nd domain)201✅x@notconfigured.com400 "Mailbox domain must be one of the configured DOMAINS"✅npm run typecheck🤖 Generated with Claude Code