1- 'use strict' ;
2-
3-
4-
51const path = require ( 'path' ) ;
62const _ = require ( 'lodash' ) ;
73const yaml = require ( 'js-yaml' ) ;
@@ -24,33 +20,27 @@ class ServerlessAWSFunctionURLCustomDomainPlugin {
2420 const filename = path . resolve ( __dirname , 'resources.yml' ) ;
2521 const content = fs . readFileSync ( filename , 'utf-8' ) ;
2622 const resources = yaml . load ( content , {
27- filename : filename
23+ filename,
2824 } ) ;
2925
3026 this . prepareResources ( resources ) ;
3127 const combinedResouces = _ . merge ( baseResources , resources ) ;
3228 return combinedResouces ;
33-
3429 }
3530
3631 printSummary ( ) {
37- const cloudTemplate = this . serverless ;
3832
39- const awsInfo = _ . find ( this . serverless . pluginManager . getPlugins ( ) , ( plugin ) => {
40- return plugin . constructor . name === 'AwsInfo' ;
41- } ) ;
33+ const awsInfo = _ . find ( this . serverless . pluginManager . getPlugins ( ) , ( plugin ) => plugin . constructor . name === 'AwsInfo' ) ;
4234
4335 if ( ! awsInfo || ! awsInfo . gatheredData ) {
4436 return ;
4537 }
4638
47- const outputs = awsInfo . gatheredData . outputs ;
48- const apiDistributionDomain = _ . find ( outputs , ( output ) => {
49- return output . OutputKey === 'ApiCloudFrontDistributionDomain' ;
50- } ) ;
39+ const { outputs } = awsInfo . gatheredData ;
40+ const apiDistributionDomain = _ . find ( outputs , ( output ) => output . OutputKey === 'ApiCloudFrontDistributionDomain' ) ;
5141
5242 if ( ! apiDistributionDomain || ! apiDistributionDomain . OutputValue ) {
53- return ;
43+ return ;
5444 }
5545
5646 const cnameDomain = this . getConfig ( 'apiDomain' , '-' ) ;
@@ -59,20 +49,20 @@ class ServerlessAWSFunctionURLCustomDomainPlugin {
5949 this . serverless . cli . consoleLog ( ` ${ apiDistributionDomain . OutputValue } (CNAME: ${ cnameDomain } )` ) ;
6050 }
6151
62-
6352 prepareResources ( resources ) {
6453 const distributionConfig = resources . Resources . ApiCloudFrontDistribution . Properties . DistributionConfig ;
6554 const apiRecordsConfig = resources . Resources . ApiRecordSetGroup . Properties ;
6655 this . prepareDomain ( distributionConfig , apiRecordsConfig ) ;
6756 this . prepareAcmCertificateArn ( distributionConfig ) ;
6857 this . prepareHostedZoneName ( apiRecordsConfig ) ;
69-
7058 }
59+
7160 prepareHostedZoneName ( apiRecordsConfig ) {
7261 const name = this . getConfig ( 'hostedZoneName' , null ) ;
7362
7463 apiRecordsConfig . HostedZoneName = name ;
7564 }
65+
7666 prepareAcmCertificateArn ( distributionConfig ) {
7767 const arn = this . getConfig ( 'certificateNVirginaArn' , null ) ;
7868 distributionConfig . ViewerCertificate . AcmCertificateArn = arn ;
@@ -82,22 +72,18 @@ class ServerlessAWSFunctionURLCustomDomainPlugin {
8272 const domain = this . getConfig ( 'apiDomain' , null ) ;
8373
8474 if ( domain !== null ) {
85- const domains = Array . isArray ( domain ) ? domain : [ domain ]
75+ const domains = Array . isArray ( domain ) ? domain : [ domain ] ;
8676 distributionConfig . Aliases = domains ;
87- apiRecordsConfig . RecordSets [ 0 ] . Name = domains [ 0 ] ;
88- distributionConfig . Comment = ' Api distribution for ' + domains [ 0 ] ;
77+ apiRecordsConfig . RecordSets [ 0 ] . Name = domains [ 0 ] ;
78+ distributionConfig . Comment = ` Api distribution for ${ domains [ 0 ] } ` ;
8979 } else {
9080 delete distributionConfig . Aliases ;
9181 }
9282 }
9383
94-
95-
96-
9784 getConfig ( field , defaultValue ) {
98- return _ . get ( this . serverless , `service.custom.urlDomain.${ field } ` , defaultValue )
85+ return _ . get ( this . serverless , `service.custom.urlDomain.${ field } ` , defaultValue ) ;
9986 }
100-
10187}
10288
10389module . exports = ServerlessAWSFunctionURLCustomDomainPlugin ;
0 commit comments