diff --git a/.changeset/fresh-taxis-trade.md b/.changeset/fresh-taxis-trade.md new file mode 100644 index 000000000..7f5bcfb24 --- /dev/null +++ b/.changeset/fresh-taxis-trade.md @@ -0,0 +1,5 @@ +--- +'@gradientedge/cdk-utils-cloudflare': patch +--- + +feat: Cloudflare static add dependency between route and worker diff --git a/packages/cloudflare/src/construct/worker-site/main.ts b/packages/cloudflare/src/construct/worker-site/main.ts index 3ee34a4cc..e03f1d355 100644 --- a/packages/cloudflare/src/construct/worker-site/main.ts +++ b/packages/cloudflare/src/construct/worker-site/main.ts @@ -113,12 +113,17 @@ export class CloudflareWorkerSite extends CommonCloudflareConstruct { * @summary Create the worker domain */ protected createWorkerDomain() { - this.siteWorkerDomain = this.workerManager.createWorkerDomain(`${this.id}-worker-domain`, this, { - ...this.props.siteWorkerDomain, - environment: this.props.siteWorkerDomain.environment ?? 'production', - hostname: `${this.props.siteSubDomain}.${this.props.domainName}`, - service: this.siteWorkerScript.scriptName, - }) + this.siteWorkerDomain = this.workerManager.createWorkerDomain( + `${this.id}-worker-domain`, + this, + { + ...this.props.siteWorkerDomain, + environment: this.props.siteWorkerDomain.environment ?? 'production', + hostname: `${this.props.siteSubDomain}.${this.props.domainName}`, + service: this.siteWorkerScript.scriptName, + }, + { dependsOn: [this.siteWorkerScript] } + ) } /** diff --git a/packages/cloudflare/src/services/worker/main.ts b/packages/cloudflare/src/services/worker/main.ts index 5d1a4515b..1b5ae79f0 100644 --- a/packages/cloudflare/src/services/worker/main.ts +++ b/packages/cloudflare/src/services/worker/main.ts @@ -6,6 +6,7 @@ import { WorkersRoute, WorkersScript, } from '@pulumi/cloudflare' +import { ResourceOptions } from '@pulumi/pulumi' import _ from 'lodash' import { CommonCloudflareConstruct } from '../../common/index.js' @@ -45,7 +46,12 @@ export class CloudflareWorkerManager { * @param props worker domain properties * @see [Pulumi Worker Domain]{@link https://www.pulumi.com/registry/packages/cloudflare/api-docs/workercustomdomain/} */ - public createWorkerDomain(id: string, scope: CommonCloudflareConstruct, props: WorkerDomainProps) { + public createWorkerDomain( + id: string, + scope: CommonCloudflareConstruct, + props: WorkerDomainProps, + resourceOptions?: ResourceOptions + ) { if (!props) throw new Error(`Props undefined for ${id}`) const zoneId = props.zoneId @@ -58,7 +64,7 @@ export class CloudflareWorkerManager { accountId: props.accountId ?? scope.props.accountId, zoneId, }, - { parent: scope } + { parent: scope, ...resourceOptions } ) }