quidproquo-deploy-awscdk 0.0.147 → 0.0.149
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/constructs/feature/webserver/redirect/QpqWebserverSubdomainRedirectConstruct.js +27 -0
- package/lib/commonjs/lambdas/lambdaAPIGatewayEvent_redirect.js +3 -1
- package/lib/commonjs/stacks/ApiQpqServiceStack.js +1 -1
- package/package.json +1 -1
- package/src/constructs/feature/webserver/redirect/QpqWebserverSubdomainRedirectConstruct.ts +38 -0
- package/src/lambdas/lambdaAPIGatewayEvent_redirect.ts +5 -1
- package/src/stacks/ApiQpqServiceStack.ts +4 -4
package/lib/commonjs/constructs/feature/webserver/redirect/QpqWebserverSubdomainRedirectConstruct.js
CHANGED
|
@@ -7,6 +7,7 @@ const QpqConstructBlock_1 = require("../../../base/QpqConstructBlock");
|
|
|
7
7
|
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
8
8
|
const SubdomainName_1 = require("../../../basic/SubdomainName");
|
|
9
9
|
const Function_1 = require("../../../basic/Function");
|
|
10
|
+
const CloudflareDnsRecord_1 = require("../../../basic/CloudflareDnsRecord");
|
|
10
11
|
class QpqWebserverSubdomainRedirectConstruct extends QpqConstructBlock_1.QpqConstructBlock {
|
|
11
12
|
constructor(scope, id, props) {
|
|
12
13
|
super(scope, id, props);
|
|
@@ -44,6 +45,17 @@ class QpqWebserverSubdomainRedirectConstruct extends QpqConstructBlock_1.QpqCons
|
|
|
44
45
|
qpqConfig: props.qpqConfig,
|
|
45
46
|
awsAccountId: props.awsAccountId,
|
|
46
47
|
});
|
|
48
|
+
if (props.subdomainRedirectConfig.cloudflareApiKeySecretName) {
|
|
49
|
+
new CloudflareDnsRecord_1.CloudflareDnsRecord(this, 'certFlare', {
|
|
50
|
+
awsAccountId: props.awsAccountId,
|
|
51
|
+
buildPath: quidproquo_webserver_1.qpqWebServerUtils.getRedirectApiBuildFullPath(props.qpqConfig, props.subdomainRedirectConfig),
|
|
52
|
+
qpqConfig: props.qpqConfig,
|
|
53
|
+
// certificateArn: subdomain.certificate.certificateArn,
|
|
54
|
+
certificateDomain: serviceDomainName.deployDomain,
|
|
55
|
+
dnsEntries: {},
|
|
56
|
+
apiSecretName: props.subdomainRedirectConfig.cloudflareApiKeySecretName,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
47
59
|
// Map all requests to this service to /serviceName/*
|
|
48
60
|
new aws_cdk_lib_1.aws_apigateway.BasePathMapping(this, 'base-path-mapping', {
|
|
49
61
|
domainName: serviceDomainName.domainName,
|
|
@@ -51,6 +63,21 @@ class QpqWebserverSubdomainRedirectConstruct extends QpqConstructBlock_1.QpqCons
|
|
|
51
63
|
// the properties below are optional
|
|
52
64
|
// basePath: settings.service,
|
|
53
65
|
});
|
|
66
|
+
if (props.subdomainRedirectConfig.cloudflareApiKeySecretName) {
|
|
67
|
+
new CloudflareDnsRecord_1.CloudflareDnsRecord(this, 'cloudflare', {
|
|
68
|
+
awsAccountId: props.awsAccountId,
|
|
69
|
+
buildPath: quidproquo_webserver_1.qpqWebServerUtils.getRedirectApiBuildFullPath(props.qpqConfig, props.subdomainRedirectConfig),
|
|
70
|
+
qpqConfig: props.qpqConfig,
|
|
71
|
+
dnsEntries: {
|
|
72
|
+
[serviceDomainName.deployDomain]: {
|
|
73
|
+
value: serviceDomainName.domainName.domainNameAliasDomainName,
|
|
74
|
+
proxied: true,
|
|
75
|
+
type: 'CNAME',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
apiSecretName: props.subdomainRedirectConfig.cloudflareApiKeySecretName,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
54
81
|
}
|
|
55
82
|
}
|
|
56
83
|
exports.QpqWebserverSubdomainRedirectConstruct = QpqWebserverSubdomainRedirectConstruct;
|
|
@@ -11,13 +11,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.executeAPIGatewayEvent = void 0;
|
|
13
13
|
const executeAPIGatewayEvent = (event, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
// console.log('event: ', JSON.stringify(event, null, 2));
|
|
15
|
+
// console.log('process.env: ', JSON.stringify(process.env, null, 2));
|
|
14
16
|
const redirectConfig = JSON.parse(process.env.redirectConfig);
|
|
15
17
|
// For direct urls ~ Go straight to the url
|
|
16
18
|
let redirectUrl = redirectConfig.redirectUrl;
|
|
17
19
|
// Otherwise it must be a domain redirect
|
|
18
20
|
if (!redirectConfig.redirectUrl.startsWith('http')) {
|
|
19
21
|
const environment = JSON.parse(process.env.environment);
|
|
20
|
-
const featureEnvironment = JSON.parse(process.env.featureEnvironment);
|
|
22
|
+
const featureEnvironment = JSON.parse(process.env.featureEnvironment || '""');
|
|
21
23
|
let baseDomain = redirectConfig.redirectUrl;
|
|
22
24
|
if (redirectConfig.addEnvironment) {
|
|
23
25
|
baseDomain = `${environment}.${baseDomain}`;
|
|
@@ -38,7 +38,7 @@ class ApiQpqServiceStack extends QpqServiceStack_1.QpqServiceStack {
|
|
|
38
38
|
queueConfig: setting,
|
|
39
39
|
apiLayerVersions: layers.layers,
|
|
40
40
|
}));
|
|
41
|
-
//
|
|
41
|
+
// Redirects
|
|
42
42
|
const redirects = quidproquo_webserver_1.qpqWebServerUtils.getSubdomainRedirects(props.qpqConfig).map((setting) => new constructs_1.QpqWebserverSubdomainRedirectConstruct(this, quidproquo_core_1.qpqCoreUtils.getUniqueKeyForSetting(setting), {
|
|
43
43
|
awsAccountId: props.awsAccountId,
|
|
44
44
|
qpqConfig: props.qpqConfig,
|
package/package.json
CHANGED
|
@@ -15,6 +15,7 @@ import { SubdomainName } from '../../../basic/SubdomainName';
|
|
|
15
15
|
|
|
16
16
|
import { Function } from '../../../basic/Function';
|
|
17
17
|
import * as qpqDeployAwsCdkUtils from '../../../../utils';
|
|
18
|
+
import { CloudflareDnsRecord } from '../../../basic/CloudflareDnsRecord';
|
|
18
19
|
|
|
19
20
|
export interface QpqWebserverSubdomainRedirectConstructProps extends QpqConstructBlockProps {
|
|
20
21
|
subdomainRedirectConfig: SubdomainRedirectQPQWebServerConfigSetting;
|
|
@@ -69,6 +70,23 @@ export class QpqWebserverSubdomainRedirectConstruct extends QpqConstructBlock {
|
|
|
69
70
|
awsAccountId: props.awsAccountId,
|
|
70
71
|
});
|
|
71
72
|
|
|
73
|
+
if (props.subdomainRedirectConfig.cloudflareApiKeySecretName) {
|
|
74
|
+
new CloudflareDnsRecord(this, 'certFlare', {
|
|
75
|
+
awsAccountId: props.awsAccountId,
|
|
76
|
+
buildPath: qpqWebServerUtils.getRedirectApiBuildFullPath(
|
|
77
|
+
props.qpqConfig,
|
|
78
|
+
props.subdomainRedirectConfig,
|
|
79
|
+
),
|
|
80
|
+
qpqConfig: props.qpqConfig,
|
|
81
|
+
|
|
82
|
+
// certificateArn: subdomain.certificate.certificateArn,
|
|
83
|
+
certificateDomain: serviceDomainName.deployDomain,
|
|
84
|
+
|
|
85
|
+
dnsEntries: {},
|
|
86
|
+
apiSecretName: props.subdomainRedirectConfig.cloudflareApiKeySecretName,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
72
90
|
// Map all requests to this service to /serviceName/*
|
|
73
91
|
new aws_apigateway.BasePathMapping(this, 'base-path-mapping', {
|
|
74
92
|
domainName: serviceDomainName.domainName,
|
|
@@ -77,5 +95,25 @@ export class QpqWebserverSubdomainRedirectConstruct extends QpqConstructBlock {
|
|
|
77
95
|
// the properties below are optional
|
|
78
96
|
// basePath: settings.service,
|
|
79
97
|
});
|
|
98
|
+
|
|
99
|
+
if (props.subdomainRedirectConfig.cloudflareApiKeySecretName) {
|
|
100
|
+
new CloudflareDnsRecord(this, 'cloudflare', {
|
|
101
|
+
awsAccountId: props.awsAccountId,
|
|
102
|
+
buildPath: qpqWebServerUtils.getRedirectApiBuildFullPath(
|
|
103
|
+
props.qpqConfig,
|
|
104
|
+
props.subdomainRedirectConfig,
|
|
105
|
+
),
|
|
106
|
+
qpqConfig: props.qpqConfig,
|
|
107
|
+
|
|
108
|
+
dnsEntries: {
|
|
109
|
+
[serviceDomainName.deployDomain]: {
|
|
110
|
+
value: serviceDomainName.domainName.domainNameAliasDomainName,
|
|
111
|
+
proxied: true,
|
|
112
|
+
type: 'CNAME',
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
apiSecretName: props.subdomainRedirectConfig.cloudflareApiKeySecretName,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
80
118
|
}
|
|
81
119
|
}
|
|
@@ -2,6 +2,9 @@ import { APIGatewayEvent, Context } from 'aws-lambda';
|
|
|
2
2
|
import { SubdomainRedirectQPQWebServerConfigSetting } from 'quidproquo-webserver';
|
|
3
3
|
|
|
4
4
|
export const executeAPIGatewayEvent = async (event: APIGatewayEvent, context: Context) => {
|
|
5
|
+
// console.log('event: ', JSON.stringify(event, null, 2));
|
|
6
|
+
// console.log('process.env: ', JSON.stringify(process.env, null, 2));
|
|
7
|
+
|
|
5
8
|
const redirectConfig: SubdomainRedirectQPQWebServerConfigSetting = JSON.parse(
|
|
6
9
|
process.env.redirectConfig as string,
|
|
7
10
|
);
|
|
@@ -14,8 +17,9 @@ export const executeAPIGatewayEvent = async (event: APIGatewayEvent, context: Co
|
|
|
14
17
|
const environment: SubdomainRedirectQPQWebServerConfigSetting = JSON.parse(
|
|
15
18
|
process.env.environment as string,
|
|
16
19
|
);
|
|
20
|
+
|
|
17
21
|
const featureEnvironment: SubdomainRedirectQPQWebServerConfigSetting = JSON.parse(
|
|
18
|
-
process.env.featureEnvironment as string,
|
|
22
|
+
(process.env.featureEnvironment as string | undefined) || '""',
|
|
19
23
|
);
|
|
20
24
|
|
|
21
25
|
let baseDomain = redirectConfig.redirectUrl;
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
QpqWebserverServiceFunctionConstruct,
|
|
15
15
|
QpqApiWebserverWebsocketConstruct,
|
|
16
16
|
QpqCoreDeployEventConstruct,
|
|
17
|
-
QpqApiCoreStorageDriveConstruct
|
|
17
|
+
QpqApiCoreStorageDriveConstruct,
|
|
18
18
|
} from '../constructs';
|
|
19
19
|
|
|
20
20
|
export interface ApiQpqServiceStackProps extends QpqServiceStackProps {
|
|
@@ -72,7 +72,7 @@ export class ApiQpqServiceStack extends QpqServiceStack {
|
|
|
72
72
|
}),
|
|
73
73
|
);
|
|
74
74
|
|
|
75
|
-
//
|
|
75
|
+
// Redirects
|
|
76
76
|
const redirects = qpqWebServerUtils.getSubdomainRedirects(props.qpqConfig).map(
|
|
77
77
|
(setting) =>
|
|
78
78
|
new QpqWebserverSubdomainRedirectConstruct(
|
|
@@ -103,8 +103,8 @@ export class ApiQpqServiceStack extends QpqServiceStack {
|
|
|
103
103
|
),
|
|
104
104
|
);
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
// Build websocket apis
|
|
107
|
+
const websockets = qpqWebServerUtils.getWebsocketSettings(props.qpqConfig).map(
|
|
108
108
|
(setting) =>
|
|
109
109
|
new QpqApiWebserverWebsocketConstruct(this, qpqCoreUtils.getUniqueKeyForSetting(setting), {
|
|
110
110
|
awsAccountId: props.awsAccountId,
|