fix(cli): keep the Functions suffix for self-hosted function rules - #1918
Merged
Merged
Conversation
ruleDomains prepended _APP_DOMAIN_SITES to the Functions candidate list for every endpoint, and ensureDefaultRule takes domains[0] whenever the config carries no previewDomainLabel. On Cloud that is harmless, since the Sites suffix there is appwrite.network, which is also the Functions edge suffix. Self-hosted, the two products have unrelated domains, so `appwrite push functions` minted the function's default rule under the Sites suffix. The Cloud selector that would have sorted this out never runs on a self-hosted push: functionDomainForTarget is only reached when a label is present, and `pull functions` records previewDomainLabel only for .appwrite.network and .appwrite.run domains. Gate the prepend on a Cloud endpoint so Cloud ordering is unchanged and a self-hosted install resolves its own Functions suffix. The new test drives runPushDeployable against an httptest server and asserts the domain that arrives at POST /proxy/rules/function, so it covers the domains[0] pick rather than restating ruleDomains' own input.
Contributor
|
ChiragAgg5k
approved these changes
Sep 18, 2026
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.
Fixes appwrite/appwrite#13743. Replaces appwrite/sdk-for-cli#365, which patched the generated output instead of the template.
What happens
On a self-hosted install,
appwrite push functionsgives a newly created function a default proxy rule under the Sites domain:Why
ruleDomainsprepends_APP_DOMAIN_SITESto the Functions candidate list for every endpoint, andensureDefaultRuletakesdomains[0]whenever the config carries nopreviewDomainLabel:On Cloud that is harmless — the Sites suffix there is
appwrite.network, which is also the Functions edge suffix, and leading with it is what letsfunctionDomainForTargetpick edge vs. region. Self-hosted, the two products have unrelated domains, so the Sites suffix simply wins.Nothing downstream corrects it:
functionDomainForTargetonly runs when a label is present (label != "" && resource.Name == "function"), andpull functionsrecordspreviewDomainLabelonly for.appwrite.network/.appwrite.rundomains — so on self-hosted the label is always empty.regionalRuleDomainandcloudFunctionDomainsare both no-ops off Cloud.validateDomainRestrictionspermits one label under either product suffix, and the router resolves by hostname and re-derives the product from the deployment, so the mismatch never surfaces.The issue's repro needs its delete step because
ensureDefaultRuleshort-circuits onlabel == "" && len(items) > 0— deleting the function cascades its rules away, so the re-push falls through to rule creation.Introduced in CLI 27.2.0, which replaced
body.Set("domain", appwrite.Unique()+"."+domains[0])with the label/target logic and added the prepend.The change
Gate the prepend on a Cloud endpoint. Cloud ordering is unchanged; a self-hosted install resolves its own Functions suffix.
Tests
TestSelfHostedPushRulesOnTheFunctionsDomaindrivesrunPushDeployableagainst anhttptestserver and asserts the domain that arrives atPOST /proxy/rules/function— so it coversensureDefaultRule'sdomains[0]pick, not justruleDomains. Against the unfixed template it reproduces the reported symptom:TestRuleDomainsKeepsEdgeGlobalAndRegionalisesComputepasses unmodified, which pins that Cloud ordering is untouched.Regenerated per the pre-submit checklist:
gofmt -l examples/cliclean,composer lint-twigandcomposer refactor:checkpass.