quidproquo-deploy-awscdk 0.0.78 → 0.0.80
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/constructs/feature/webserver/redirect/QpqWebserverSubdomainRedirectConstruct.js +17 -39
- package/lib/constructs/feature/webserver/webEntry/QpqWebserverWebEntryConstruct.js +6 -0
- package/lib/lambdas/lambdaAPIGatewayEvent_redirect.js +14 -15
- package/lib/stacks/ApiQpqServiceStack.js +6 -0
- package/package.json +1 -1
- package/src/constructs/feature/webserver/redirect/QpqWebserverSubdomainRedirectConstruct.ts +27 -13
- package/src/constructs/feature/webserver/webEntry/QpqWebserverWebEntryConstruct.ts +7 -0
- package/src/lambdas/lambdaAPIGatewayEvent_redirect.ts +19 -17
- package/src/stacks/ApiQpqServiceStack.ts +16 -0
|
@@ -1,68 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
3
|
exports.QpqWebserverSubdomainRedirectConstruct = void 0;
|
|
30
|
-
const path_1 = __importDefault(require("path"));
|
|
31
|
-
const cdk = __importStar(require("aws-cdk-lib"));
|
|
32
4
|
const quidproquo_core_1 = require("quidproquo-core");
|
|
5
|
+
const quidproquo_webserver_1 = require("quidproquo-webserver");
|
|
33
6
|
const QpqConstructBlock_1 = require("../../../base/QpqConstructBlock");
|
|
34
7
|
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
35
8
|
const SubdomainName_1 = require("../../../basic/SubdomainName");
|
|
9
|
+
const Function_1 = require("../../../basic/Function");
|
|
36
10
|
class QpqWebserverSubdomainRedirectConstruct extends QpqConstructBlock_1.QpqConstructBlock {
|
|
37
11
|
constructor(scope, id, props) {
|
|
38
12
|
super(scope, id, props);
|
|
39
|
-
const buildPath = quidproquo_core_1.qpqCoreUtils.getBuildPath(props.qpqConfig);
|
|
40
13
|
const environment = quidproquo_core_1.qpqCoreUtils.getApplicationModuleEnvironment(props.qpqConfig);
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
14
|
+
const feature = quidproquo_core_1.qpqCoreUtils.getApplicationModuleFeature(props.qpqConfig);
|
|
15
|
+
const func = new Function_1.Function(this, 'redirect', {
|
|
16
|
+
buildPath: quidproquo_webserver_1.qpqWebServerUtils.getRedirectApiBuildFullPath(props.qpqConfig, props.subdomainRedirectConfig),
|
|
17
|
+
functionName: this.resourceName(`${props.subdomainRedirectConfig.subdomain}-redirect`),
|
|
18
|
+
functionType: 'lambdaAPIGatewayEvent_redirect',
|
|
19
|
+
executorName: 'executeAPIGatewayEvent',
|
|
20
|
+
qpqConfig: props.qpqConfig,
|
|
48
21
|
environment: {
|
|
49
22
|
redirectConfig: JSON.stringify(props.subdomainRedirectConfig),
|
|
50
23
|
environment: JSON.stringify(environment),
|
|
24
|
+
featureEnvironment: JSON.stringify(feature),
|
|
51
25
|
},
|
|
26
|
+
awsAccountId: props.awsAccountId,
|
|
52
27
|
});
|
|
53
28
|
const restApi = new aws_cdk_lib_1.aws_apigateway.LambdaRestApi(this, 'rest-api', {
|
|
54
29
|
restApiName: this.resourceName(`${props.subdomainRedirectConfig.subdomain}-redirect`),
|
|
55
|
-
handler:
|
|
30
|
+
handler: func.lambdaFunction,
|
|
56
31
|
deployOptions: {
|
|
57
32
|
loggingLevel: aws_cdk_lib_1.aws_apigateway.MethodLoggingLevel.INFO,
|
|
58
33
|
dataTraceEnabled: true,
|
|
59
34
|
},
|
|
60
35
|
proxy: true,
|
|
61
36
|
});
|
|
62
|
-
//
|
|
37
|
+
// www.service.domain.com or www.domain.com
|
|
38
|
+
const apexDomain = props.subdomainRedirectConfig.onRootDomain
|
|
39
|
+
? quidproquo_webserver_1.qpqWebServerUtils.getBaseDomainName(props.qpqConfig)
|
|
40
|
+
: quidproquo_webserver_1.qpqWebServerUtils.getServiceDomainName(props.qpqConfig);
|
|
63
41
|
const serviceDomainName = new SubdomainName_1.SubdomainName(this, 'service-domain-name', {
|
|
64
42
|
subdomain: props.subdomainRedirectConfig.subdomain,
|
|
65
|
-
apexDomain
|
|
43
|
+
apexDomain,
|
|
66
44
|
qpqConfig: props.qpqConfig,
|
|
67
45
|
awsAccountId: props.awsAccountId,
|
|
68
46
|
});
|
|
@@ -110,6 +110,7 @@ class QpqWebserverWebEntryConstruct extends QpqConstructBlock_1.QpqConstructBloc
|
|
|
110
110
|
defaultBehavior: {
|
|
111
111
|
origin: distributionOrigin,
|
|
112
112
|
cachePolicy: cachePolicy,
|
|
113
|
+
viewerProtocolPolicy: aws_cdk_lib_1.aws_cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
113
114
|
},
|
|
114
115
|
domainNames: [deployDomain],
|
|
115
116
|
certificate: myCertificate,
|
|
@@ -121,6 +122,11 @@ class QpqWebserverWebEntryConstruct extends QpqConstructBlock_1.QpqConstructBloc
|
|
|
121
122
|
responsePagePath: '/',
|
|
122
123
|
})),
|
|
123
124
|
});
|
|
125
|
+
props.webEntryConfig.ignoreCache.forEach((pathPattern) => {
|
|
126
|
+
distribution.addBehavior(pathPattern, distributionOrigin, {
|
|
127
|
+
cachePolicy: aws_cdk_lib_1.aws_cloudfront.CachePolicy.CACHING_DISABLED,
|
|
128
|
+
});
|
|
129
|
+
});
|
|
124
130
|
// TODO: Fix this when they add l2 support for origin access control settings
|
|
125
131
|
// Currently distribution don't have support for origin access control settings
|
|
126
132
|
// So we manually add it.
|
|
@@ -13,26 +13,25 @@ exports.executeAPIGatewayEvent = void 0;
|
|
|
13
13
|
const executeAPIGatewayEvent = (event, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
14
|
const redirectConfig = JSON.parse(process.env.redirectConfig);
|
|
15
15
|
// For direct urls ~ Go straight to the url
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
statusCode: 301,
|
|
19
|
-
body: '',
|
|
20
|
-
headers: {
|
|
21
|
-
Location: redirectConfig.redirectUrl,
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
}
|
|
16
|
+
let redirectUrl = redirectConfig.redirectUrl;
|
|
25
17
|
// Otherwise it must be a domain redirect
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
if (!redirectConfig.redirectUrl.startsWith('http')) {
|
|
19
|
+
const environment = JSON.parse(process.env.environment);
|
|
20
|
+
const featureEnvironment = JSON.parse(process.env.featureEnvironment);
|
|
21
|
+
let baseDomain = redirectConfig.redirectUrl;
|
|
22
|
+
if (redirectConfig.addEnvironment) {
|
|
23
|
+
baseDomain = `${environment}.${baseDomain}`;
|
|
24
|
+
}
|
|
25
|
+
if (redirectConfig.addFeatureEnvironment && featureEnvironment) {
|
|
26
|
+
baseDomain = `${featureEnvironment}.${baseDomain}`;
|
|
27
|
+
}
|
|
28
|
+
redirectUrl = `https://${baseDomain}${event.path}`;
|
|
29
|
+
}
|
|
31
30
|
return {
|
|
32
31
|
statusCode: 301,
|
|
33
32
|
body: '',
|
|
34
33
|
headers: {
|
|
35
|
-
Location:
|
|
34
|
+
Location: redirectUrl,
|
|
36
35
|
},
|
|
37
36
|
};
|
|
38
37
|
});
|
|
@@ -37,6 +37,12 @@ class ApiQpqServiceStack extends QpqServiceStack_1.QpqServiceStack {
|
|
|
37
37
|
queueConfig: setting,
|
|
38
38
|
apiLayerVersions: layers.layers,
|
|
39
39
|
}));
|
|
40
|
+
// Queues
|
|
41
|
+
const redirects = quidproquo_webserver_1.qpqWebServerUtils.getSubdomainRedirects(props.qpqConfig).map((setting) => new constructs_1.QpqWebserverSubdomainRedirectConstruct(this, quidproquo_core_1.qpqCoreUtils.getUniqueKeyForSetting(setting), {
|
|
42
|
+
awsAccountId: props.awsAccountId,
|
|
43
|
+
qpqConfig: props.qpqConfig,
|
|
44
|
+
subdomainRedirectConfig: setting,
|
|
45
|
+
}));
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
48
|
exports.ApiQpqServiceStack = ApiQpqServiceStack;
|
package/package.json
CHANGED
|
@@ -2,7 +2,10 @@ import path from 'path';
|
|
|
2
2
|
import * as cdk from 'aws-cdk-lib';
|
|
3
3
|
|
|
4
4
|
import { qpqCoreUtils } from 'quidproquo-core';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
SubdomainRedirectQPQWebServerConfigSetting,
|
|
7
|
+
qpqWebServerUtils,
|
|
8
|
+
} from 'quidproquo-webserver';
|
|
6
9
|
|
|
7
10
|
import { QpqConstructBlock, QpqConstructBlockProps } from '../../../base/QpqConstructBlock';
|
|
8
11
|
|
|
@@ -10,6 +13,9 @@ import { Construct } from 'constructs';
|
|
|
10
13
|
import { aws_lambda, aws_apigateway } from 'aws-cdk-lib';
|
|
11
14
|
import { SubdomainName } from '../../../basic/SubdomainName';
|
|
12
15
|
|
|
16
|
+
import { Function } from '../../../basic/Function';
|
|
17
|
+
import * as qpqDeployAwsCdkUtils from '../../../../utils';
|
|
18
|
+
|
|
13
19
|
export interface QpqWebserverSubdomainRedirectConstructProps extends QpqConstructBlockProps {
|
|
14
20
|
subdomainRedirectConfig: SubdomainRedirectQPQWebServerConfigSetting;
|
|
15
21
|
}
|
|
@@ -18,28 +24,32 @@ export class QpqWebserverSubdomainRedirectConstruct extends QpqConstructBlock {
|
|
|
18
24
|
constructor(scope: Construct, id: string, props: QpqWebserverSubdomainRedirectConstructProps) {
|
|
19
25
|
super(scope, id, props);
|
|
20
26
|
|
|
21
|
-
const buildPath = qpqCoreUtils.getBuildPath(props.qpqConfig);
|
|
22
27
|
const environment = qpqCoreUtils.getApplicationModuleEnvironment(props.qpqConfig);
|
|
28
|
+
const feature = qpqCoreUtils.getApplicationModuleFeature(props.qpqConfig);
|
|
23
29
|
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
const func = new Function(this, 'redirect', {
|
|
31
|
+
buildPath: qpqWebServerUtils.getRedirectApiBuildFullPath(
|
|
32
|
+
props.qpqConfig,
|
|
33
|
+
props.subdomainRedirectConfig,
|
|
34
|
+
),
|
|
35
|
+
functionName: this.resourceName(`${props.subdomainRedirectConfig.subdomain}-redirect`),
|
|
36
|
+
functionType: 'lambdaAPIGatewayEvent_redirect',
|
|
37
|
+
executorName: 'executeAPIGatewayEvent',
|
|
30
38
|
|
|
31
|
-
|
|
32
|
-
handler: 'index.executeAPIGatewayEvent',
|
|
39
|
+
qpqConfig: props.qpqConfig,
|
|
33
40
|
|
|
34
41
|
environment: {
|
|
35
42
|
redirectConfig: JSON.stringify(props.subdomainRedirectConfig),
|
|
36
43
|
environment: JSON.stringify(environment),
|
|
44
|
+
featureEnvironment: JSON.stringify(feature),
|
|
37
45
|
},
|
|
46
|
+
|
|
47
|
+
awsAccountId: props.awsAccountId,
|
|
38
48
|
});
|
|
39
49
|
|
|
40
50
|
const restApi = new aws_apigateway.LambdaRestApi(this, 'rest-api', {
|
|
41
51
|
restApiName: this.resourceName(`${props.subdomainRedirectConfig.subdomain}-redirect`),
|
|
42
|
-
handler:
|
|
52
|
+
handler: func.lambdaFunction,
|
|
43
53
|
deployOptions: {
|
|
44
54
|
loggingLevel: aws_apigateway.MethodLoggingLevel.INFO,
|
|
45
55
|
dataTraceEnabled: true,
|
|
@@ -47,10 +57,14 @@ export class QpqWebserverSubdomainRedirectConstruct extends QpqConstructBlock {
|
|
|
47
57
|
proxy: true,
|
|
48
58
|
});
|
|
49
59
|
|
|
50
|
-
//
|
|
60
|
+
// www.service.domain.com or www.domain.com
|
|
61
|
+
const apexDomain = props.subdomainRedirectConfig.onRootDomain
|
|
62
|
+
? qpqWebServerUtils.getBaseDomainName(props.qpqConfig)
|
|
63
|
+
: qpqWebServerUtils.getServiceDomainName(props.qpqConfig);
|
|
64
|
+
|
|
51
65
|
const serviceDomainName = new SubdomainName(this, 'service-domain-name', {
|
|
52
66
|
subdomain: props.subdomainRedirectConfig.subdomain,
|
|
53
|
-
apexDomain
|
|
67
|
+
apexDomain,
|
|
54
68
|
qpqConfig: props.qpqConfig,
|
|
55
69
|
awsAccountId: props.awsAccountId,
|
|
56
70
|
});
|
|
@@ -131,6 +131,7 @@ export class QpqWebserverWebEntryConstruct extends QpqConstructBlock {
|
|
|
131
131
|
defaultBehavior: {
|
|
132
132
|
origin: distributionOrigin,
|
|
133
133
|
cachePolicy: cachePolicy,
|
|
134
|
+
viewerProtocolPolicy: aws_cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
134
135
|
},
|
|
135
136
|
domainNames: [deployDomain],
|
|
136
137
|
certificate: myCertificate,
|
|
@@ -144,6 +145,12 @@ export class QpqWebserverWebEntryConstruct extends QpqConstructBlock {
|
|
|
144
145
|
})),
|
|
145
146
|
});
|
|
146
147
|
|
|
148
|
+
props.webEntryConfig.ignoreCache.forEach((pathPattern) => {
|
|
149
|
+
distribution.addBehavior(pathPattern, distributionOrigin, {
|
|
150
|
+
cachePolicy: aws_cloudfront.CachePolicy.CACHING_DISABLED,
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
147
154
|
// TODO: Fix this when they add l2 support for origin access control settings
|
|
148
155
|
|
|
149
156
|
// Currently distribution don't have support for origin access control settings
|
|
@@ -7,31 +7,33 @@ export const executeAPIGatewayEvent = async (event: APIGatewayEvent, context: Co
|
|
|
7
7
|
);
|
|
8
8
|
|
|
9
9
|
// For direct urls ~ Go straight to the url
|
|
10
|
-
|
|
11
|
-
return {
|
|
12
|
-
statusCode: 301,
|
|
13
|
-
body: '',
|
|
14
|
-
headers: {
|
|
15
|
-
Location: redirectConfig.redirectUrl,
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
}
|
|
10
|
+
let redirectUrl = redirectConfig.redirectUrl;
|
|
19
11
|
|
|
20
12
|
// Otherwise it must be a domain redirect
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
13
|
+
if (!redirectConfig.redirectUrl.startsWith('http')) {
|
|
14
|
+
const environment: SubdomainRedirectQPQWebServerConfigSetting = JSON.parse(
|
|
15
|
+
process.env.environment as string,
|
|
16
|
+
);
|
|
17
|
+
const featureEnvironment: SubdomainRedirectQPQWebServerConfigSetting = JSON.parse(
|
|
18
|
+
process.env.featureEnvironment as string,
|
|
19
|
+
);
|
|
27
20
|
|
|
28
|
-
|
|
21
|
+
let baseDomain = redirectConfig.redirectUrl;
|
|
22
|
+
if (redirectConfig.addEnvironment) {
|
|
23
|
+
baseDomain = `${environment}.${baseDomain}`;
|
|
24
|
+
}
|
|
25
|
+
if (redirectConfig.addFeatureEnvironment && featureEnvironment) {
|
|
26
|
+
baseDomain = `${featureEnvironment}.${baseDomain}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
redirectUrl = `https://${baseDomain}${event.path}`;
|
|
30
|
+
}
|
|
29
31
|
|
|
30
32
|
return {
|
|
31
33
|
statusCode: 301,
|
|
32
34
|
body: '',
|
|
33
35
|
headers: {
|
|
34
|
-
Location:
|
|
36
|
+
Location: redirectUrl,
|
|
35
37
|
},
|
|
36
38
|
};
|
|
37
39
|
};
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
QpqCoreRecurringScheduleConstruct,
|
|
12
12
|
QpqWebserverApiConstruct,
|
|
13
13
|
QpqApiCoreQueueConstruct,
|
|
14
|
+
QpqWebserverSubdomainRedirectConstruct,
|
|
14
15
|
} from '../constructs';
|
|
15
16
|
|
|
16
17
|
export interface ApiQpqServiceStackProps extends QpqServiceStackProps {
|
|
@@ -68,5 +69,20 @@ export class ApiQpqServiceStack extends QpqServiceStack {
|
|
|
68
69
|
apiLayerVersions: layers.layers,
|
|
69
70
|
}),
|
|
70
71
|
);
|
|
72
|
+
|
|
73
|
+
// Queues
|
|
74
|
+
const redirects = qpqWebServerUtils.getSubdomainRedirects(props.qpqConfig).map(
|
|
75
|
+
(setting) =>
|
|
76
|
+
new QpqWebserverSubdomainRedirectConstruct(
|
|
77
|
+
this,
|
|
78
|
+
qpqCoreUtils.getUniqueKeyForSetting(setting),
|
|
79
|
+
{
|
|
80
|
+
awsAccountId: props.awsAccountId,
|
|
81
|
+
qpqConfig: props.qpqConfig,
|
|
82
|
+
|
|
83
|
+
subdomainRedirectConfig: setting,
|
|
84
|
+
},
|
|
85
|
+
),
|
|
86
|
+
);
|
|
71
87
|
}
|
|
72
88
|
}
|