Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions alchemy-web/src/content/docs/providers/cloudflare/bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,50 @@ console.log(publicBucket.domain); // [random-id].r2.dev

This enables the `r2.dev` domain for the bucket. This URL is rate-limited and not recommended for production use.

## With Custom Domain

Serve bucket content through your own domain with automatic DNS configuration:

```ts
import { R2Bucket, Zone } from "alchemy/cloudflare";

// Option 1: Using a Zone resource (domain can be derived from zone)
const zone = await Zone("my-zone", { name: "example.com" });

const cdnBucket = await R2Bucket("cdn-assets", {
name: "cdn-assets",
customDomain: {
domain: "cdn.example.com", // Optional when using Zone resource
zone: zone, // Pass the Zone resource directly
enabled: true,
minTLS: "1.2", // Minimum TLS version (1.0, 1.1, 1.2, 1.3)
},
});

// Option 2: Using a zone ID string (domain is required)
const cdnBucket2 = await R2Bucket("cdn-assets-2", {
name: "cdn-assets-2",
customDomain: {
domain: "cdn2.example.com", // Required when using zone ID string
zone: "your-zone-id", // Cloudflare Zone ID as string
enabled: true,
minTLS: "1.2",
},
});

// DNS record is automatically created as a proxied CNAME to public.r2.dev
console.log(cdnBucket.customDomain?.domain); // "cdn.example.com"
```

The custom domain feature:

- Automatically creates a proxied CNAME DNS record pointing to `public.r2.dev`
- Handles DNS record cleanup when the custom domain is removed
- Supports TLS configuration and cipher suite customization
- Provides ownership verification and SSL certificate status
- Accepts either a Zone resource or zone ID string for the `zone` property
- When using a Zone resource, the `domain` can be derived from the zone's name if not explicitly provided

## With CORS

Create a bucket with CORS rules:
Expand Down Expand Up @@ -210,7 +254,6 @@ const bucket = await R2Bucket("my-bucket", {
});
```


### `head`

Retrieve metadata about an object.
Expand Down Expand Up @@ -254,4 +297,4 @@ List objects in the bucket.
```ts
const list = await bucket.list();
console.log(list.objects.length);
```
```
Loading