-
Notifications
You must be signed in to change notification settings - Fork 46
feat(cloudflare): add CustomHostname resour 8000 ce for Cloudflare for SaaS #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sam-goodwin
wants to merge
3
commits into
main
Choose a base branch
from
claude/issue-435-20250620_110432
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
833c235
feat(cloudflare): add CustomHostname resource for Cloudflare for SaaS
claude[bot] f0c7768
refactor(cloudflare): address PR review feedback for CustomHostname
claude[bot] b9befa9
refactor: revert deepEquals to explicit field checking in CustomHostname
claude[bot] File filter 8000
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
189 changes: 189 additions & 0 deletions
189
alchemy-web/docs/providers/cloudflare/custom-hostname.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
# CustomHostname | ||
|
||
Create and manage Custom Hostnames for Cloudflare for SaaS. Custom Hostnames allow you to provide SSL certificates for your customer's domains that point to your Cloudflare zone. | ||
|
||
Learn more about [Cloudflare for SaaS domain support](https://developers.cloudflare.com/cloudflare-for-platforms/cloudflare-for-saas/domain-support/). | ||
|
||
## Example Usage | ||
|
||
### Basic Custom Hostname | ||
|
||
Create a custom hostname with default SSL settings: | ||
|
||
```ts | ||
import { Zone, CustomHostname } from "@alchemy/cloudflare"; | ||
|
||
const zone = await Zone("example-zone", { | ||
name: "example.com" | ||
}); | ||
|
||
const customHostname = await CustomHostname("customer-hostname", { | ||
hostname: "app.customer.com", | ||
zone: zone, | ||
ssl: { | ||
method: "http", | ||
type: "dv" | ||
} | ||
}); | ||
|
||
console.log(`Custom hostname ID: ${customHostname.id}`); | ||
console.log(`Status: ${customHostname.status}`); | ||
console.log(`SSL Status: ${customHostname.ssl.status}`); | ||
``` | ||
|
||
### Custom Hostname with Advanced SSL Settings | ||
|
||
Create a custom hostname with specific SSL configuration: | ||
|
||
```ts | ||
const customHostname = await CustomHostname("secure-hostname", { | ||
hostname: "secure.customer.com", | ||
zone: "your-zone-id", | ||
ssl: { | ||
method: "txt", | ||
type: "dv", | ||
settings: { | ||
http2: "on", | ||
tls_1_3: "on", | ||
min_tls_version: "1.2" | ||
}, | ||
bundle_method: "optimal" | ||
}, | ||
custom_metadata: { | ||
customer_id: "12345", | ||
plan: "enterprise" | ||
} | ||
}); | ||
``` | ||
|
||
### Custom Hostname with Wildcard Certificate | ||
|
||
Create a wildcard custom hostname: | ||
|
||
```ts | ||
const wildcardHostname = await CustomHostname("wildcard-hostname", { | ||
hostname: "*.customer.com", | ||
zone: zone, | ||
ssl: { | ||
method: "txt", | ||
type: "dv", | ||
wildcard: true, | ||
bundle_method: "ubiquitous" | ||
} | ||
}); | ||
``` | ||
|
||
## Properties | ||
|
||
### Required Properties | ||
|
||
| Property | Type | Description | | ||
|----------|------|-------------| | ||
| `hostname` | `string` | The custom hostname to create (e.g., "app.customer.com") | | ||
| `zone` | `string \| Zone` | The zone where the custom hostname will be created | | ||
|
||
### Optional Properties | ||
|
||
| Property | Type | Description | | ||
|----------|------|-------------| | ||
| `ssl` | `CustomHostnameSslSettings` | SSL configuration for the hostname | | ||
| `custom_metadata` | `Record<string, string>` | Custom metadata key-value pairs | | ||
|
||
### SSL Settings | ||
|
||
| Property | Type | Default | Description | | ||
|----------|------|---------|-------------| | ||
| `method` | `"http" \| "txt" \| "email"` | `"http"` | SSL certificate validation method | | ||
| `type` | `"dv"` | `"dv"` | SSL certificate type (Domain Validated) | | ||
| `bundle_method` | `"ubiquitous" \| "optimal" \| "force_ubiquitous"` | `"ubiquitous"` | Certificate bundle method | | ||
| `wildcard` | `boolean` | `false` | Enable wildcard certificate | | ||
| `settings` | `object` | - | Advanced SSL settings | | ||
|
||
### Advanced SSL Settings | ||
|
||
| Property | Type | Default | Description | | ||
|----------|------|---------|-------------| | ||
| `http2` | `"on" \| "off"` | `"on"` | Enable HTTP/2 | | ||
| `tls_1_3` | `"on" \| "off"` | `"on"` | Enable TLS 1.3 | | ||
| `min_tls_version` | `"1.0" \| "1.1" \| "1.2" \| "1.3"` | `"1.2"` | Minimum TLS version | | ||
| `ciphers` | `string[]` | - | Custom cipher list | | ||
|
||
## Outputs | ||
|
||
| Property | Type | Description | | ||
|----------|------|-------------| | ||
| `id` | `string` | Unique identifier for the custom hostname | | ||
| `zoneId` | `string` | Zone ID where the hostname was created | | ||
| `status` | `string` | Current status of the custom hostname | | ||
| `ssl` | `object` | SSL certificate information and status | | ||
| `ownershipVerification` | `object` | Ownership verification details | | ||
| `ownershipVerificationHttp` | `object` | HTTP verification details (if applicable) | | ||
| `verificationErrors` | `string[]` | Any verification errors | | ||
| `createdAt` | `number` | Creation timestamp | | ||
| `modifiedAt` | `number` | Last modification timestamp | | ||
|
||
## Status Values | ||
|
||
Custom hostnames can have the following status values: | ||
|
||
- `pending_validation` - Waiting for domain validation | ||
- `pending_issuance` - SSL certificate being issued | ||
- `pending_deployment` - SSL certificate being deployed | ||
- `active` - Custom hostname is active and ready to use | ||
- `moved` - Hostname moved to different account | ||
- `deleted` - Hostname has been deleted | ||
|
||
## SSL Verification Methods | ||
|
||
### HTTP Verification (`method: "http"`) | ||
|
||
With HTTP verification, Cloudflare will make an HTTP request to verify domain ownership: | ||
|
||
```ts | ||
// Access verification details from the hostname output | ||
if (customHostname.ownershipVerificationHttp) { | ||
console.log(`Place this content: ${customHostname.ownershipVerificationHttp.httpBody}`); | ||
console.log(`At this URL: ${customHostname.ownershipVerificationHttp.httpUrl}`); | ||
} | ||
``` | ||
|
||
### TXT Record Verification (`method: "txt"`) | ||
|
||
With TXT verification, you need to create a DNS TXT record: | ||
|
||
```ts | ||
// Access verification details from the hostname output | ||
if (customHostname.ownershipVerification) { | ||
console.log(`Create TXT record: ${customHostname.ownershipVerification.name}`); | ||
console.log(`With value: ${customHostname.ownershipVerification.value}`); | ||
} | ||
``` | ||
|
||
## Error Handling | ||
|
||
Check for verification errors: | ||
|
||
```ts | ||
if (customHostname.verificationErrors && customHostname.verificationErrors.length > 0) { | ||
console.error("Verification errors:", customHostname.verificationErrors); | ||
} | ||
``` | ||
|
||
## Best Practices | ||
|
||
1. **Use TXT verification for production** - More secure than HTTP verification | ||
2. **Monitor status** - Check the status and verification errors regularly | ||
3. **Use metadata for tracking** - Store customer information in custom_metadata | ||
4. **Choose appropriate bundle method** - Use "optimal" for better performance, "ubiquitous" for compatibility | ||
5. **Enable modern TLS settings** - Use TLS 1.3 and modern cipher suites when possible | ||
|
||
## Related Resources | ||
|
||
- [Zone](./zone.md) - Cloudflare zone management | ||
- [CustomDomain](./custom-domain.md) - Worker custom domains | ||
- [DNS Records](./dns-records.md) - DNS record management | ||
|
||
## Reference | ||
|
||
- [Cloudflare Custom Hostnames API](https://developers.cloudflare.com/api/resources/custom_hostnames/) | ||
- [Cloudflare for SaaS Documentation](https://developers.cloudflare.com/cloudflare-for-platforms/cloudflare-for-saas/) |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link to https://developers.cloudflare.com/cloudflare-for-platforms/cloudflare-for-saas/domain-support/