Skip to content

Commit 4205477

Browse files
authored
Merge pull request #183 from devsapp/support/check-domain-dns
Support/check domain dns
2 parents 133d1ae + 9c05f28 commit 4205477

File tree

2 files changed

+56
-18
lines changed

2 files changed

+56
-18
lines changed

src/index.ts

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,36 @@ export default class FcDeployComponent {
119119
(needDeployAll && type !== 'code') || (!command && type !== 'code') || command === 'trigger';
120120
let needDeployAllTriggers = true;
121121

122+
// deploy custom domain
123+
let hasAutoCustomDomainNameInDomains = false;
124+
const resolvedCustomDomainConfs: CustomDomainConfig[] = [];
125+
const needDeployDomain = needDeployAll || (!command && type !== 'code') || command === 'domain';
126+
if (!_.isEmpty(this.fcCustomDomains) && needDeployDomain) {
127+
logger.spinner?.stop();
128+
const spin = core.spinner('Generated auto custom domain...');
129+
try {
130+
for (let i = 0; i < this.fcCustomDomains.length; i++) {
131+
await this.fcCustomDomains[i].initLocal(useLocal, useRemote, _.cloneDeep(inputs));
132+
if (this.fcCustomDomains[i].useRemote) {
133+
continue;
134+
}
135+
const resolvedCustomDomainConf: CustomDomainConfig = await this.fcCustomDomains[
136+
i
137+
].makeCustomDomain(this.args, this.credentials);
138+
hasAutoCustomDomainNameInDomains =
139+
hasAutoCustomDomainNameInDomains || this.fcCustomDomains[i].isDomainNameAuto;
140+
resolvedCustomDomainConfs.push(resolvedCustomDomainConf);
141+
logger.debug(
142+
`resolved custom domain: \n${JSON.stringify(resolvedCustomDomainConf, null, ' ')}`,
143+
);
144+
}
145+
spin.succeed('Generated auto custom domain succeed');
146+
} catch (error) {
147+
spin.fail('Generated auto custom domain failed');
148+
throw error;
149+
}
150+
}
151+
122152
await logger.task('Checking', [
123153
{
124154
title: `Checking Service ${this.fcService?.name} exists`,
@@ -359,29 +389,21 @@ export default class FcDeployComponent {
359389
}
360390
}
361391

362-
// deploy custom domain
363-
let hasAutoCustomDomainNameInDomains = false;
364-
const resolvedCustomDomainConfs: CustomDomainConfig[] = [];
365-
const needDeployDomain = needDeployAll || (!command && type !== 'code') || command === 'domain';
366392
await logger.task('Creating custom domain', [
367393
{
368-
title: 'Generated auto custom domain...',
369-
enabled: () => !_.isEmpty(this.fcCustomDomains) && needDeployDomain,
394+
title: 'Check domain config auto dns...',
395+
enabled: () => !_.isEmpty(resolvedCustomDomainConfs),
370396
task: async () => {
371-
for (let i = 0; i < this.fcCustomDomains.length; i++) {
372-
await this.fcCustomDomains[i].initLocal(useLocal, useRemote, _.cloneDeep(inputs));
373-
if (this.fcCustomDomains[i].useRemote) {
397+
for (const fcCustomDomain of this.fcCustomDomains) {
398+
if (fcCustomDomain.useRemote || !fcCustomDomain.isDomainNameAuto) {
374399
continue;
375400
}
376-
const resolvedCustomDomainConf: CustomDomainConfig = await this.fcCustomDomains[
377-
i
378-
].makeCustomDomain(this.args, this.credentials);
379-
hasAutoCustomDomainNameInDomains =
380-
hasAutoCustomDomainNameInDomains || this.fcCustomDomains[i].isDomainNameAuto;
381-
resolvedCustomDomainConfs.push(resolvedCustomDomainConf);
382-
logger.debug(
383-
`resolved custom domain: \n${JSON.stringify(resolvedCustomDomainConf, null, ' ')}`,
384-
);
401+
logger.debug(`check domain props: ${fcCustomDomain.customDomainConf.domainName}`);
402+
try {
403+
await fcCustomDomain.checkCname();
404+
} catch (ex) {
405+
logger.debug(`check domain dns error: ${ex.message}`);
406+
}
385407
}
386408
},
387409
},

src/lib/fc/custom-domain.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,20 @@ export class FcCustomDomain extends IInputsBase {
294294

295295
return resolvedCustomDomainConf;
296296
}
297+
298+
async checkCname(): Promise<boolean> {
299+
const domainComponentInputs = {
300+
..._.cloneDeep(this.serverlessProfile),
301+
props: {
302+
region: this.region,
303+
domain: this.customDomainConf.domainName,
304+
},
305+
};
306+
logger.spinner?.stop();
307+
const domainComponentIns = await core.load('devsapp/domain');
308+
logger.spinner?.start();
309+
const status = await domainComponentIns.checkCname(domainComponentInputs);
310+
logger.debug(`check domain status: ${status}`);
311+
return status;
312+
}
297313
}

0 commit comments

Comments
 (0)