Skip to content

Commit b7a7cd2

Browse files
committed
fix: enable workers.dev subdomain after deployment
- Add enableSubdomain() method to CloudflareDeployer - Call enableSubdomain() after worker deployment - Use POST method to enable subdomain (not PUT) - Increase retry404 from 0 to 5 for propagation delays - Requires Workers Scripts:Edit permission on API token This fixes the issue where deployed workers weren't accessible on workers.dev due to subdomain not being enabled. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Lars Trieloff <lars@trieloff.net>
1 parent 32e8a43 commit b7a7cd2

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/CloudflareDeployer.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ export default class CloudflareDeployer extends BaseDeployer {
8989
await this.updatePackageParams(id, this.cfg.packageParams);
9090

9191
await this.restoreSettings(settings);
92+
93+
await this.enableSubdomain();
9294
}
9395

9496
async getSettings() {
@@ -120,6 +122,22 @@ export default class CloudflareDeployer extends BaseDeployer {
120122
return res.ok;
121123
}
122124

125+
async enableSubdomain() {
126+
const res = await this.fetch(`https://api.cloudflare.com/client/v4/accounts/${this._cfg.accountID}/workers/scripts/${this.fullFunctionName}/subdomain`, {
127+
method: 'POST',
128+
headers: {
129+
Authorization: `Bearer ${this._cfg.auth}`,
130+
'content-type': 'application/json',
131+
},
132+
body: JSON.stringify({ enabled: true }),
133+
});
134+
if (!res.ok) {
135+
const { errors } = await res.json();
136+
this.log.warn(`Unable to enable workers.dev subdomain: ${errors[0]?.message || 'unknown error'}`);
137+
}
138+
return res.ok;
139+
}
140+
123141
async updatePackageParams(id, params) {
124142
const kvlist = Object.entries(params).map(([key, value]) => ({
125143
key, value,
@@ -169,7 +187,7 @@ export default class CloudflareDeployer extends BaseDeployer {
169187
? this.testRequest({
170188
url: `https://${this.fullFunctionName}.${this._cfg.testDomain}.workers.dev`,
171189
idHeader: 'CF-RAY',
172-
retry404: 0,
190+
retry404: 5,
173191
})
174192
: undefined;
175193
}

0 commit comments

Comments
 (0)