Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for HTTP and WebSocket Domain Names
- Loading branch information
Showing
9 changed files
with
956 additions
and
438 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* Wrapper class for Custom Domain information | ||
*/ | ||
|
||
import Globals from "./Globals"; | ||
import DomainInfo = require("./DomainInfo"); | ||
|
||
class DomainConfig { | ||
|
||
public givenDomainName: string; | ||
public basePath: string | undefined; | ||
public stage: string | undefined; | ||
public certificateName: string | undefined; | ||
public certificateArn: string | undefined; | ||
public createRoute53Record: boolean | undefined; | ||
public endpointType: string | undefined; | ||
public apiType: string | undefined; | ||
public hostedZoneId: string | undefined; | ||
public hostedZonePrivate: boolean | undefined; | ||
public enabled: boolean | string | undefined; | ||
public securityPolicy: string | undefined; | ||
|
||
public apiId: string | undefined; | ||
public domainInfo: DomainInfo | undefined; | ||
public currentBasePath: string | undefined; | ||
|
||
constructor(config: any) { | ||
|
||
this.enabled = this.evaluateEnabled(config.enabled); | ||
this.givenDomainName = config.domainName; | ||
this.hostedZonePrivate = config.hostedZonePrivate; | ||
this.certificateArn = config.certificateArn; | ||
this.certificateName = config.certificateName; | ||
this.createRoute53Record = config.createRoute53Record; | ||
this.hostedZoneId = config.hostedZoneId; | ||
this.hostedZonePrivate = config.hostedZonePrivate; | ||
|
||
let basePath = config.basePath; | ||
if (basePath == null || basePath.trim() === "") { | ||
basePath = "(none)"; | ||
} | ||
this.basePath = basePath; | ||
|
||
let stage = config.stage; | ||
if (typeof stage === "undefined") { | ||
stage = Globals.options.stage || Globals.serverless.service.provider.stage; | ||
} | ||
this.stage = stage; | ||
|
||
const endpointTypeWithDefault = config.endpointType || Globals.endpointTypes.edge; | ||
const endpointTypeToUse = Globals.endpointTypes[endpointTypeWithDefault.toLowerCase()]; | ||
if (!endpointTypeToUse) { | ||
throw new Error(`${endpointTypeWithDefault} is not supported endpointType, use edge or regional.`); | ||
} | ||
this.endpointType = endpointTypeToUse; | ||
|
||
const apiTypeWithDefault = config.apiType || Globals.apiTypes.rest; | ||
const apiTypeToUse = Globals.apiTypes[apiTypeWithDefault.toLowerCase()]; | ||
if (!apiTypeToUse) { | ||
throw new Error(`${apiTypeWithDefault} is not supported api type, use REST, HTTP or WEBSOCKET.`); | ||
} | ||
this.apiType = apiTypeToUse; | ||
|
||
const securityPolicyDefault = config.securityPolicy || Globals.tlsVersions.tls_1_2; | ||
const tlsVersionToUse = Globals.tlsVersions[securityPolicyDefault.toLowerCase()]; | ||
if (!tlsVersionToUse) { | ||
throw new Error(`${securityPolicyDefault} is not a supported securityPolicy, use tls_1_0 or tls_1_2.`); | ||
} | ||
this.securityPolicy = tlsVersionToUse; | ||
} | ||
|
||
/** | ||
* Determines whether this plug-in is enabled. | ||
* | ||
* This method reads the customDomain property "enabled" to see if this plug-in should be enabled. | ||
* If the property's value is undefined, a default value of true is assumed (for backwards | ||
* compatibility). | ||
* If the property's value is provided, this should be boolean, otherwise an exception is thrown. | ||
* If no customDomain object exists, an exception is thrown. | ||
*/ | ||
public evaluateEnabled(enabled: any): boolean { | ||
// const enabled = this.serverless.service.custom.customDomain.enabled; | ||
if (enabled === undefined) { | ||
return true; | ||
} | ||
if (typeof enabled === "boolean") { | ||
return enabled; | ||
} else if (typeof enabled === "string" && enabled === "true") { | ||
return true; | ||
} else if (typeof enabled === "string" && enabled === "false") { | ||
return false; | ||
} | ||
throw new Error(`serverless-domain-manager: Ambiguous enablement boolean: "${enabled}"`); | ||
} | ||
} | ||
|
||
export = DomainConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ServerlessInstance, ServerlessOptions } from "./types"; | ||
|
||
export default class Globals { | ||
|
||
public static serverless: ServerlessInstance; | ||
public static options: ServerlessOptions; | ||
|
||
public static endpointTypes = { | ||
edge: "EDGE", | ||
regional: "REGIONAL", | ||
}; | ||
|
||
public static apiTypes = { | ||
http: "HTTP", | ||
rest: "REST", | ||
websocket: "WEBSOCKET", | ||
}; | ||
|
||
public static tlsVersions = { | ||
tls_1_0: "TLS_1_0", | ||
tls_1_2: "TLS_1_2", | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.