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.
@@ -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 redirectLambda = new aws_cdk_lib_1.aws_lambda.Function(this, 'lambda', {
42
- functionName: this.resourceName(`redirect-${props.subdomainRedirectConfig.subdomain}`),
43
- timeout: cdk.Duration.seconds(25),
44
- runtime: aws_cdk_lib_1.aws_lambda.Runtime.NODEJS_18_X,
45
- memorySize: 128,
46
- code: aws_cdk_lib_1.aws_lambda.Code.fromAsset(path_1.default.join(buildPath, 'lambdaAPIGatewayEvent_redirect')),
47
- handler: 'index.executeAPIGatewayEvent',
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: redirectLambda,
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
- // TODO: Fix this
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
- if (redirectConfig.redirectUrl.startsWith('http')) {
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
- const environment = JSON.parse(process.env.environment);
27
- const baseDomain = redirectConfig.addFeatureEnvironment
28
- ? `${environment}.${redirectConfig.redirectUrl}`
29
- : redirectConfig.redirectUrl;
30
- const fullUrl = `https://${baseDomain}${event.path}`;
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: fullUrl,
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-deploy-awscdk",
3
- "version": "0.0.78",
3
+ "version": "0.0.80",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.js",
@@ -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 { SubdomainRedirectQPQWebServerConfigSetting } from 'quidproquo-webserver';
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 redirectLambda = new aws_lambda.Function(this, 'lambda', {
25
- functionName: this.resourceName(`redirect-${props.subdomainRedirectConfig.subdomain}`),
26
- timeout: cdk.Duration.seconds(25),
27
-
28
- runtime: aws_lambda.Runtime.NODEJS_18_X,
29
- memorySize: 128,
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
- code: aws_lambda.Code.fromAsset(path.join(buildPath, 'lambdaAPIGatewayEvent_redirect')),
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: redirectLambda,
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
- // TODO: Fix this
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
- if (redirectConfig.redirectUrl.startsWith('http')) {
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
- const environment: SubdomainRedirectQPQWebServerConfigSetting = JSON.parse(
22
- process.env.environment as string,
23
- );
24
- const baseDomain = redirectConfig.addFeatureEnvironment
25
- ? `${environment}.${redirectConfig.redirectUrl}`
26
- : redirectConfig.redirectUrl;
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
- const fullUrl = `https://${baseDomain}${event.path}`;
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: fullUrl,
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
  }