Skip to content
Open
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
1 change: 1 addition & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
- run: npm run integration-ci
env:
HLX_FASTLY_AUTH: ${{ secrets.HLX_FASTLY_AUTH }}
CLOUDFLARE_AUTH: ${{ secrets.CLOUDFLARE_AUTH }}

- name: Semantic Release (Dry Run)
run: npm run semantic-release-dry
Expand Down
20 changes: 19 additions & 1 deletion src/CloudflareDeployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export default class CloudflareDeployer extends BaseDeployer {
await this.updatePackageParams(id, this.cfg.packageParams);

await this.restoreSettings(settings);

await this.enableSubdomain();
}

async getSettings() {
Expand Down Expand Up @@ -120,6 +122,22 @@ export default class CloudflareDeployer extends BaseDeployer {
return res.ok;
}

async enableSubdomain() {
const res = await this.fetch(`https://api.cloudflare.com/client/v4/accounts/${this._cfg.accountID}/workers/scripts/${this.fullFunctionName}/subdomain`, {
method: 'POST',
headers: {
Authorization: `Bearer ${this._cfg.auth}`,
'content-type': 'application/json',
},
body: JSON.stringify({ enabled: true }),
});
if (!res.ok) {
const { errors } = await res.json();
this.log.warn(`Unable to enable workers.dev subdomain: ${errors[0]?.message || 'unknown error'}`);
}
return res.ok;
}

async updatePackageParams(id, params) {
const kvlist = Object.entries(params).map(([key, value]) => ({
key, value,
Expand Down Expand Up @@ -169,7 +187,7 @@ export default class CloudflareDeployer extends BaseDeployer {
? this.testRequest({
url: `https://${this.fullFunctionName}.${this._cfg.testDomain}.workers.dev`,
idHeader: 'CF-RAY',
retry404: 0,
retry404: 5,
})
: undefined;
}
Expand Down
9 changes: 5 additions & 4 deletions test/cloudflare.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Cloudflare Integration Test', () => {
await fse.remove(testRoot);
});

it.skip('Deploy a pure action to Cloudflare', async () => {
it('Deploy a pure action to Cloudflare', async () => {
await fse.copy(path.resolve(__rootdir, 'test', 'fixtures', 'edge-action'), testRoot);
process.chdir(testRoot); // need to change .cwd() for yargs to pickup `wsk` in package.json
const builder = await new CLI()
Expand All @@ -47,8 +47,9 @@ describe('Cloudflare Integration Test', () => {
'--plugin', path.resolve(__rootdir, 'src', 'index.js'),
'--arch', 'edge',
'--cloudflare-email', 'lars@trieloff.net',
'--cloudflare-account-id', 'b4adf6cfdac0918eb6aa5ad033da0747',
'--cloudflare-test-domain', 'rockerduck',
'--cloudflare-account-id', '155ec15a52a18a14801e04b019da5e5a',
'--cloudflare-test-domain', 'minivelos',
'--cloudflare-auth', process.env.CLOUDFLARE_AUTH,
'--package.params', 'HEY=ho',
'--package.params', 'ZIP=zap',
'--update-package', 'true',
Expand All @@ -64,6 +65,6 @@ describe('Cloudflare Integration Test', () => {
const res = await builder.run();
assert.ok(res);
const out = builder.cfg._logger.output;
assert.ok(out.indexOf('https://simple-package--simple-project.rockerduck.workers.dev') > 0, out);
assert.ok(out.indexOf('https://simple-package--simple-project.minivelos.workers.dev') > 0, out);
}).timeout(10000000);
});
8 changes: 6 additions & 2 deletions test/deploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ describe('Deploy Test', () => {
})
.reply(200, JSON.stringify({ result: { id: 'test-namespace' } }))
.put('/client/v4/accounts/123/workers/scripts/default--test-worker')
.reply(200);
.reply(200)
.post('/client/v4/accounts/123/workers/scripts/default--test-worker/subdomain')
.reply(200, JSON.stringify({ result: { enabled: true, previews_enabled: true } }));

process.chdir(testRoot); // need to change .cwd() for yargs to pickup `wsk` in package.json
const builder = await new CLI()
Expand Down Expand Up @@ -120,7 +122,9 @@ describe('Deploy Test', () => {
bodies.settings = b;
return true;
})
.reply(200);
.reply(200)
.post('/client/v4/accounts/123/workers/scripts/default--test-worker/subdomain')
.reply(200, JSON.stringify({ result: { enabled: true, previews_enabled: true } }));

process.chdir(testRoot); // need to change .cwd() for yargs to pickup `wsk` in package.json
const builder = await new CLI()
Expand Down
Loading