-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
94 lines (83 loc) · 3.21 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"use strict";
const DomainNameService = require("./lib/services/domain-name-service");
const BasePathMappingService = require("./lib/services/base-path-mapping-service");
const RecordSetService = require("./lib/services/record-set-service");
class CustomDomainPlugin {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options;
this.commands = {
"create-domain": {
usage: "Creates custom domain name resource in API Gateway. This requires a certificate in Amazon Certificate Manager to be registered.",
lifecycleEvents: [
"create-domain"
]
},
"remove-domain": {
usage: "Removes the specified custom domain name resource from API Gateway.",
lifecycleEvents: [
"remove-domain"
]
},
"create-record": {
usage: "Creates a record set in the specified hosted zone with the cloud front addres from the specified domain name.",
lifecycleEvents: [
"create-record"
]
},
"remove-record": {
usage: "Removes the specified record set from the specified hosted zone.",
lifecycleEvents: [
"remove-record"
]
},
"create-mapping": {
usage: "Creates a base path mapping for the current API Gateway in the provided custom domain name.",
lifecycleEvents: [
"create-mapping"
]
},
"remove-mapping": {
usage: "Removes a base path mapping from the current API Gateway in the provided custom domain name.",
lifecycleEvents: [
"remove-mapping"
]
}
};
this.hooks = {
"create-domain:create-domain": this.createDomain.bind(this),
"remove-domain:remove-domain": this.removeDomain.bind(this),
"create-record:create-record": this.createRecord.bind(this),
"remove-record:remove-record": this.removeRecord.bind(this),
"create-mapping:create-mapping": this.createMapping.bind(this),
"remove-mapping:remove-mapping": this.removeMapping.bind(this)
};
}
createDomain() {
const domainNameService = new DomainNameService(this.serverless, this.options, this.serverless.cli);
return domainNameService.createApiNameAsync();
}
removeDomain() {
const domainNameService = new DomainNameService(this.serverless, this.options, this.serverless.cli);
return domainNameService.removeApiNameAsync();
}
createRecord() {
const domainNameService = new DomainNameService(this.serverless, this.options, this.serverless.cli);
const recordSetService = new RecordSetService(this.serverless, this.options, this.serverless.cli, domainNameService);
return recordSetService.createRecordSetAsync();
}
removeRecord() {
const domainNameService = new DomainNameService(this.serverless, this.options, this.serverless.cli);
const recordSetService = new RecordSetService(this.serverless, this.options, this.serverless.cli, domainNameService);
return recordSetService.removeRecordSetAsync();
}
createMapping() {
const basePathMappingService = new BasePathMappingService(this.serverless, this.options, this.serverless.cli);
return basePathMappingService.createBasePathMappingAsync();
}
removeMapping() {
const basePathMappingService = new BasePathMappingService(this.serverless, this.options, this.serverless.cli);
return basePathMappingService.removeBasePathMappingAsync();
}
}
module.exports = CustomDomainPlugin;