quidproquo-deploy-awscdk 0.0.65 → 0.0.67
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.
|
@@ -96,11 +96,20 @@ class QpqWebserverWebEntryConstruct extends QpqConstruct_1.QpqConstruct {
|
|
|
96
96
|
description: `access to s3 bucket ${this.resourceName(originBucket.bucketName)}`,
|
|
97
97
|
},
|
|
98
98
|
});
|
|
99
|
+
const cachePolicy = new aws_cdk_lib_1.aws_cloudfront.CachePolicy(this, `dist-cp`, {
|
|
100
|
+
cachePolicyName: this.resourceName(props.setting.name),
|
|
101
|
+
defaultTtl: cdk.Duration.seconds(props.setting.cache.defaultTTLInSeconds),
|
|
102
|
+
minTtl: cdk.Duration.seconds(props.setting.cache.minTTLInSeconds),
|
|
103
|
+
maxTtl: cdk.Duration.seconds(props.setting.cache.maxTTLInSeconds),
|
|
104
|
+
enableAcceptEncodingGzip: true,
|
|
105
|
+
enableAcceptEncodingBrotli: true,
|
|
106
|
+
});
|
|
99
107
|
// Create a CloudFront distribution using the S3 bucket as the origin
|
|
100
108
|
const distributionOrigin = new aws_cdk_lib_1.aws_cloudfront_origins.S3Origin(originBucket);
|
|
101
109
|
const distribution = new aws_cdk_lib_1.aws_cloudfront.Distribution(this, 'MyDistribution', {
|
|
102
110
|
defaultBehavior: {
|
|
103
111
|
origin: distributionOrigin,
|
|
112
|
+
cachePolicy: cachePolicy,
|
|
104
113
|
},
|
|
105
114
|
domainNames: [deployDomain],
|
|
106
115
|
certificate: myCertificate,
|
|
@@ -157,8 +166,18 @@ class QpqWebserverWebEntryConstruct extends QpqConstruct_1.QpqConstruct {
|
|
|
157
166
|
if (seo.deprecated) {
|
|
158
167
|
continue;
|
|
159
168
|
}
|
|
169
|
+
const seoCachePolicy = new aws_cdk_lib_1.aws_cloudfront.CachePolicy(this, `seo-cp-${seo.uniqueKey}`, {
|
|
170
|
+
cachePolicyName: this.resourceName(`${props.setting.name}-${seo.uniqueKey}`),
|
|
171
|
+
headerBehavior: aws_cdk_lib_1.aws_cloudfront.CacheHeaderBehavior.allowList(quidproquo_webserver_1.qpqHeaderIsBot, ...seo.cache.headers),
|
|
172
|
+
defaultTtl: cdk.Duration.seconds(seo.cache.defaultTTLInSeconds),
|
|
173
|
+
minTtl: cdk.Duration.seconds(seo.cache.minTTLInSeconds),
|
|
174
|
+
maxTtl: cdk.Duration.seconds(seo.cache.maxTTLInSeconds),
|
|
175
|
+
enableAcceptEncodingGzip: true,
|
|
176
|
+
enableAcceptEncodingBrotli: true,
|
|
177
|
+
});
|
|
160
178
|
const wildcardPath = seo.path.replaceAll(/{(.+?)}/g, '*');
|
|
161
179
|
distribution.addBehavior(wildcardPath, distributionOrigin, {
|
|
180
|
+
cachePolicy: seoCachePolicy,
|
|
162
181
|
edgeLambdas: [
|
|
163
182
|
{
|
|
164
183
|
functionVersion: edgeFunctionVR.currentVersion,
|
|
@@ -10,18 +10,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.executeEventViewerRequest = exports.getViewerRequestEventExecutor = void 0;
|
|
13
|
+
const quidproquo_webserver_1 = require("quidproquo-webserver");
|
|
13
14
|
const getViewerRequestEventExecutor = () => {
|
|
14
15
|
return (event, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
16
|
var _a;
|
|
16
17
|
console.log(JSON.stringify(event));
|
|
17
18
|
const request = event.Records[0].cf.request;
|
|
18
19
|
const headers = request.headers;
|
|
19
|
-
const customUserAgentHeaderName = 'x-qpq-is-bot';
|
|
20
20
|
const userAgent = ((_a = headers['user-agent'][0]) === null || _a === void 0 ? void 0 : _a.value) || 'unknown';
|
|
21
21
|
let isBot = userAgent.match(/bot|crawl|spider|slurp|facebot|facebookexternalhit/i);
|
|
22
|
-
return Object.assign(Object.assign({}, request), { headers: Object.assign(Object.assign({}, request.headers), { [
|
|
22
|
+
return Object.assign(Object.assign({}, request), { headers: Object.assign(Object.assign({}, request.headers), { [quidproquo_webserver_1.qpqHeaderIsBot]: [
|
|
23
23
|
{
|
|
24
|
-
key:
|
|
24
|
+
key: quidproquo_webserver_1.qpqHeaderIsBot,
|
|
25
25
|
value: isBot ? 'true' : 'false',
|
|
26
26
|
},
|
|
27
27
|
] }) });
|
package/package.json
CHANGED
|
@@ -13,7 +13,11 @@ import {
|
|
|
13
13
|
} from 'aws-cdk-lib';
|
|
14
14
|
import * as cdk from 'aws-cdk-lib';
|
|
15
15
|
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
WebEntryQPQWebServerConfigSetting,
|
|
18
|
+
qpqWebServerUtils,
|
|
19
|
+
qpqHeaderIsBot,
|
|
20
|
+
} from 'quidproquo-webserver';
|
|
17
21
|
import { QpqConstruct, QpqConstructProps } from './core/QpqConstruct';
|
|
18
22
|
import { Construct } from 'constructs';
|
|
19
23
|
|
|
@@ -110,11 +114,22 @@ export class QpqWebserverWebEntryConstruct extends QpqConstruct<WebEntryQPQWebSe
|
|
|
110
114
|
},
|
|
111
115
|
);
|
|
112
116
|
|
|
117
|
+
const cachePolicy = new aws_cloudfront.CachePolicy(this, `dist-cp`, {
|
|
118
|
+
cachePolicyName: this.resourceName(props.setting.name),
|
|
119
|
+
defaultTtl: cdk.Duration.seconds(props.setting.cache.defaultTTLInSeconds),
|
|
120
|
+
minTtl: cdk.Duration.seconds(props.setting.cache.minTTLInSeconds),
|
|
121
|
+
maxTtl: cdk.Duration.seconds(props.setting.cache.maxTTLInSeconds),
|
|
122
|
+
|
|
123
|
+
enableAcceptEncodingGzip: true,
|
|
124
|
+
enableAcceptEncodingBrotli: true,
|
|
125
|
+
});
|
|
126
|
+
|
|
113
127
|
// Create a CloudFront distribution using the S3 bucket as the origin
|
|
114
128
|
const distributionOrigin = new aws_cloudfront_origins.S3Origin(originBucket);
|
|
115
129
|
const distribution = new aws_cloudfront.Distribution(this, 'MyDistribution', {
|
|
116
130
|
defaultBehavior: {
|
|
117
131
|
origin: distributionOrigin,
|
|
132
|
+
cachePolicy: cachePolicy,
|
|
118
133
|
},
|
|
119
134
|
domainNames: [deployDomain],
|
|
120
135
|
certificate: myCertificate,
|
|
@@ -211,9 +226,22 @@ export class QpqWebserverWebEntryConstruct extends QpqConstruct<WebEntryQPQWebSe
|
|
|
211
226
|
continue;
|
|
212
227
|
}
|
|
213
228
|
|
|
214
|
-
const
|
|
229
|
+
const seoCachePolicy = new aws_cloudfront.CachePolicy(this, `seo-cp-${seo.uniqueKey}`, {
|
|
230
|
+
cachePolicyName: this.resourceName(`${props.setting.name}-${seo.uniqueKey}`),
|
|
231
|
+
headerBehavior: aws_cloudfront.CacheHeaderBehavior.allowList(
|
|
232
|
+
qpqHeaderIsBot,
|
|
233
|
+
...seo.cache.headers,
|
|
234
|
+
),
|
|
235
|
+
defaultTtl: cdk.Duration.seconds(seo.cache.defaultTTLInSeconds),
|
|
236
|
+
minTtl: cdk.Duration.seconds(seo.cache.minTTLInSeconds),
|
|
237
|
+
maxTtl: cdk.Duration.seconds(seo.cache.maxTTLInSeconds),
|
|
238
|
+
enableAcceptEncodingGzip: true,
|
|
239
|
+
enableAcceptEncodingBrotli: true,
|
|
240
|
+
});
|
|
215
241
|
|
|
242
|
+
const wildcardPath = seo.path.replaceAll(/{(.+?)}/g, '*');
|
|
216
243
|
distribution.addBehavior(wildcardPath, distributionOrigin, {
|
|
244
|
+
cachePolicy: seoCachePolicy,
|
|
217
245
|
edgeLambdas: [
|
|
218
246
|
{
|
|
219
247
|
functionVersion: edgeFunctionVR.currentVersion,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CloudFrontRequestEvent, Context } from 'aws-lambda';
|
|
2
|
+
import { qpqHeaderIsBot } from 'quidproquo-webserver';
|
|
2
3
|
|
|
3
4
|
export const getViewerRequestEventExecutor = () => {
|
|
4
5
|
return async (event: CloudFrontRequestEvent, context: Context) => {
|
|
@@ -6,7 +7,7 @@ export const getViewerRequestEventExecutor = () => {
|
|
|
6
7
|
|
|
7
8
|
const request = event.Records[0].cf.request;
|
|
8
9
|
const headers = request.headers;
|
|
9
|
-
|
|
10
|
+
|
|
10
11
|
const userAgent = headers['user-agent'][0]?.value || 'unknown';
|
|
11
12
|
|
|
12
13
|
let isBot = userAgent.match(/bot|crawl|spider|slurp|facebot|facebookexternalhit/i);
|
|
@@ -15,9 +16,9 @@ export const getViewerRequestEventExecutor = () => {
|
|
|
15
16
|
...request,
|
|
16
17
|
headers: {
|
|
17
18
|
...request.headers,
|
|
18
|
-
[
|
|
19
|
+
[qpqHeaderIsBot]: [
|
|
19
20
|
{
|
|
20
|
-
key:
|
|
21
|
+
key: qpqHeaderIsBot,
|
|
21
22
|
value: isBot ? 'true' : 'false',
|
|
22
23
|
},
|
|
23
24
|
],
|