|
1 | 1 | const { Capi } = require('@tencent-sdk/capi'); |
2 | 2 | const Apis = require('./apis'); |
3 | | -const { uniqueArray, camelCaseProperty } = require('../../utils/index'); |
| 3 | +const { uniqueArray, camelCaseProperty, isArray } = require('../../utils/index'); |
4 | 4 |
|
5 | 5 | class Apigw { |
6 | 6 | constructor(credentials = {}, region) { |
@@ -511,20 +511,39 @@ class Apigw { |
511 | 511 | netType: domainItem.netType ? domainItem.netType : 'OUTER', |
512 | 512 | protocol: domainProtocol, |
513 | 513 | }; |
514 | | - await this.request({ |
515 | | - Action: 'BindSubDomain', |
516 | | - ...domainInputs, |
517 | | - }); |
518 | | - customDomainOutput.push({ |
519 | | - created: true, |
520 | | - subDomain: domainItem.domain, |
521 | | - cname: subDomain, |
522 | | - url: `${domainProtocol.indexOf('https') !== -1 ? 'https' : 'http'}://${ |
523 | | - domainItem.domain |
524 | | - }`, |
525 | | - }); |
526 | | - console.log(`Custom domain for service ${serviceId} created successfullly.`); |
527 | | - console.log(`Please add CNAME record ${subDomain} for ${domainItem.domain}.`); |
| 514 | + |
| 515 | + try { |
| 516 | + await this.request({ |
| 517 | + Action: 'BindSubDomain', |
| 518 | + ...domainInputs, |
| 519 | + }); |
| 520 | + |
| 521 | + customDomainOutput.push({ |
| 522 | + isBinded: true, |
| 523 | + created: true, |
| 524 | + subDomain: domainItem.domain, |
| 525 | + cname: subDomain, |
| 526 | + url: `${domainProtocol.indexOf('https') !== -1 ? 'https' : 'http'}://${ |
| 527 | + domainItem.domain |
| 528 | + }`, |
| 529 | + }); |
| 530 | + console.log(`Custom domain for service ${serviceId} created successfullly.`); |
| 531 | + console.log(`Please add CNAME record ${subDomain} for ${domainItem.domain}.`); |
| 532 | + } catch (e) { |
| 533 | + // User hasn't add cname dns record |
| 534 | + if (e.message.indexOf('DomainResolveError') !== -1) { |
| 535 | + customDomainOutput.push({ |
| 536 | + isBinded: false, |
| 537 | + created: '创建失败', |
| 538 | + subDomain: domainItem.domain, |
| 539 | + cname: subDomain, |
| 540 | + message: `您的自定义域名还未生效,请给域名 ${domainItem.domain} 添加 CNAME 记录 ${subDomain},等待解析生效后,再次运行 'sls deploy' 完成自定义域名的配置`, |
| 541 | + errorMsg: e.message, |
| 542 | + }); |
| 543 | + } else { |
| 544 | + throw e; |
| 545 | + } |
| 546 | + } |
528 | 547 | } |
529 | 548 | } |
530 | 549 |
|
@@ -680,7 +699,7 @@ class Apigw { |
680 | 699 | // bind custom domain |
681 | 700 | const customDomains = await this.bindCustomDomain({ |
682 | 701 | serviceId, |
683 | | - subDomain, |
| 702 | + subDomain: isArray(subDomain) ? subDomain[0] : subDomain, |
684 | 703 | inputs, |
685 | 704 | }); |
686 | 705 | if (customDomains.length > 0) { |
|
0 commit comments