sst 2.10.1 → 2.10.3
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/constructs/NextjsSite.js
CHANGED
|
@@ -267,6 +267,7 @@ export class NextjsSite extends SsrSite {
|
|
|
267
267
|
});
|
|
268
268
|
}
|
|
269
269
|
buildServerBehaviorForRegional(serverOrigin, cachePolicy, originRequestPolicy) {
|
|
270
|
+
const { cdk } = this.props;
|
|
270
271
|
return {
|
|
271
272
|
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
272
273
|
functionAssociations: this.buildBehaviorFunctionAssociations(),
|
|
@@ -275,10 +276,12 @@ export class NextjsSite extends SsrSite {
|
|
|
275
276
|
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
|
|
276
277
|
compress: true,
|
|
277
278
|
cachePolicy,
|
|
279
|
+
responseHeadersPolicy: cdk?.responseHeadersPolicy,
|
|
278
280
|
originRequestPolicy,
|
|
279
281
|
};
|
|
280
282
|
}
|
|
281
283
|
buildServerBehaviorForEdge(functionVersion, s3Origin, cachePolicy, originRequestPolicy) {
|
|
284
|
+
const { cdk } = this.props;
|
|
282
285
|
return {
|
|
283
286
|
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
284
287
|
functionAssociations: this.buildBehaviorFunctionAssociations(),
|
|
@@ -287,6 +290,7 @@ export class NextjsSite extends SsrSite {
|
|
|
287
290
|
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
|
|
288
291
|
compress: true,
|
|
289
292
|
cachePolicy,
|
|
293
|
+
responseHeadersPolicy: cdk?.responseHeadersPolicy,
|
|
290
294
|
originRequestPolicy,
|
|
291
295
|
edgeLambdas: [
|
|
292
296
|
{
|
|
@@ -298,6 +302,7 @@ export class NextjsSite extends SsrSite {
|
|
|
298
302
|
};
|
|
299
303
|
}
|
|
300
304
|
buildImageBehavior(cachePolicy) {
|
|
305
|
+
const { cdk } = this.props;
|
|
301
306
|
const imageFn = this.createImageOptimizationFunction();
|
|
302
307
|
const imageFnUrl = imageFn.addFunctionUrl({
|
|
303
308
|
authType: FunctionUrlAuthType.NONE,
|
|
@@ -309,9 +314,11 @@ export class NextjsSite extends SsrSite {
|
|
|
309
314
|
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
|
|
310
315
|
compress: true,
|
|
311
316
|
cachePolicy,
|
|
317
|
+
responseHeadersPolicy: cdk?.responseHeadersPolicy,
|
|
312
318
|
};
|
|
313
319
|
}
|
|
314
320
|
buildStaticFileBehavior(s3Origin) {
|
|
321
|
+
const { cdk } = this.props;
|
|
315
322
|
return {
|
|
316
323
|
origin: s3Origin,
|
|
317
324
|
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
@@ -319,6 +326,7 @@ export class NextjsSite extends SsrSite {
|
|
|
319
326
|
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
|
|
320
327
|
compress: true,
|
|
321
328
|
cachePolicy: CachePolicy.CACHING_OPTIMIZED,
|
|
329
|
+
responseHeadersPolicy: cdk?.responseHeadersPolicy,
|
|
322
330
|
};
|
|
323
331
|
}
|
|
324
332
|
buildDefaultNextjsBehaviorForRegional(serverOrigin, s3Origin, cachePolicy, originRequestPolicy) {
|
|
@@ -339,6 +347,7 @@ export class NextjsSite extends SsrSite {
|
|
|
339
347
|
functionAssociations: this.buildBehaviorFunctionAssociations(),
|
|
340
348
|
compress: true,
|
|
341
349
|
cachePolicy,
|
|
350
|
+
responseHeadersPolicy: cdk?.responseHeadersPolicy,
|
|
342
351
|
originRequestPolicy,
|
|
343
352
|
...(cfDistributionProps.defaultBehavior || {}),
|
|
344
353
|
};
|
|
@@ -354,6 +363,7 @@ export class NextjsSite extends SsrSite {
|
|
|
354
363
|
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
|
|
355
364
|
compress: true,
|
|
356
365
|
cachePolicy,
|
|
366
|
+
responseHeadersPolicy: cdk?.responseHeadersPolicy,
|
|
357
367
|
originRequestPolicy,
|
|
358
368
|
...(cfDistributionProps.defaultBehavior || {}),
|
|
359
369
|
edgeLambdas: [
|
package/constructs/SsrSite.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Construct } from "constructs";
|
|
|
2
2
|
import { Bucket, BucketProps, IBucket } from "aws-cdk-lib/aws-s3";
|
|
3
3
|
import { Function as CdkFunction, FunctionProps } from "aws-cdk-lib/aws-lambda";
|
|
4
4
|
import { IHostedZone } from "aws-cdk-lib/aws-route53";
|
|
5
|
-
import { Distribution, ICachePolicy, BehaviorOptions, CachePolicy, Function as CfFunction, FunctionEventType as CfFunctionEventType } from "aws-cdk-lib/aws-cloudfront";
|
|
5
|
+
import { Distribution, ICachePolicy, IResponseHeadersPolicy, BehaviorOptions, CachePolicy, Function as CfFunction, FunctionEventType as CfFunctionEventType } from "aws-cdk-lib/aws-cloudfront";
|
|
6
6
|
import { ICertificate } from "aws-cdk-lib/aws-certificatemanager";
|
|
7
7
|
import { SSTConstruct } from "./Construct.js";
|
|
8
8
|
import { NodeJSProps } from "./Function.js";
|
|
@@ -183,6 +183,11 @@ export interface SsrSiteProps {
|
|
|
183
183
|
* is one that performs no caching of the server response.
|
|
184
184
|
*/
|
|
185
185
|
serverCachePolicy?: ICachePolicy;
|
|
186
|
+
/**
|
|
187
|
+
* Override the CloudFront response headers policy properties for responses
|
|
188
|
+
* from the server rendering Lambda.
|
|
189
|
+
*/
|
|
190
|
+
responseHeadersPolicy?: IResponseHeadersPolicy;
|
|
186
191
|
server?: Pick<FunctionProps, "vpc" | "vpcSubnets" | "securityGroups" | "allowAllOutbound" | "allowPublicSubnet" | "architecture">;
|
|
187
192
|
};
|
|
188
193
|
}
|
package/constructs/SsrSite.js
CHANGED
|
@@ -547,6 +547,7 @@ function handler(event) {
|
|
|
547
547
|
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
|
|
548
548
|
compress: true,
|
|
549
549
|
cachePolicy: cdk?.serverCachePolicy ?? this.buildServerCachePolicy(),
|
|
550
|
+
responseHeadersPolicy: cdk?.responseHeadersPolicy,
|
|
550
551
|
originRequestPolicy: this.buildServerOriginRequestPolicy(),
|
|
551
552
|
...(cfDistributionProps.defaultBehavior || {}),
|
|
552
553
|
functionAssociations: [
|
|
@@ -565,6 +566,7 @@ function handler(event) {
|
|
|
565
566
|
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
|
|
566
567
|
compress: true,
|
|
567
568
|
cachePolicy: cdk?.serverCachePolicy ?? this.buildServerCachePolicy(),
|
|
569
|
+
responseHeadersPolicy: cdk?.responseHeadersPolicy,
|
|
568
570
|
originRequestPolicy: this.buildServerOriginRequestPolicy(),
|
|
569
571
|
...(cfDistributionProps.defaultBehavior || {}),
|
|
570
572
|
functionAssociations: [
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@ var file = [".js", ".jsx", ".mjs", ".cjs"].map((ext) => path.join(input.out, par
|
|
|
14
14
|
var fn;
|
|
15
15
|
function fetch(req) {
|
|
16
16
|
return new Promise((resolve, reject) => {
|
|
17
|
-
const
|
|
17
|
+
const request2 = http.request(
|
|
18
18
|
input.url + req.path,
|
|
19
19
|
{
|
|
20
20
|
headers: req.headers,
|
|
@@ -35,10 +35,10 @@ function fetch(req) {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
);
|
|
38
|
-
|
|
38
|
+
request2.on("error", reject);
|
|
39
39
|
if (req.body)
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
request2.write(req.body);
|
|
41
|
+
request2.end();
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
try {
|
|
@@ -67,15 +67,30 @@ try {
|
|
|
67
67
|
process.exit(1);
|
|
68
68
|
}
|
|
69
69
|
var timeout;
|
|
70
|
+
var request;
|
|
71
|
+
var response;
|
|
72
|
+
var context;
|
|
73
|
+
async function error(ex) {
|
|
74
|
+
await fetch({
|
|
75
|
+
path: `/runtime/invocation/${context.awsRequestId}/error`,
|
|
76
|
+
method: "POST",
|
|
77
|
+
headers: {
|
|
78
|
+
"Content-Type": "application/json"
|
|
79
|
+
},
|
|
80
|
+
body: JSON.stringify({
|
|
81
|
+
errorType: "Error",
|
|
82
|
+
errorMessage: ex.message,
|
|
83
|
+
trace: ex.stack?.split("\n")
|
|
84
|
+
})
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
process.on("unhandledRejection", error);
|
|
70
88
|
while (true) {
|
|
71
89
|
if (timeout)
|
|
72
90
|
clearTimeout(timeout);
|
|
73
91
|
timeout = setTimeout(() => {
|
|
74
92
|
process.exit(0);
|
|
75
93
|
}, 1e3 * 60 * 15);
|
|
76
|
-
let request;
|
|
77
|
-
let response;
|
|
78
|
-
let context;
|
|
79
94
|
try {
|
|
80
95
|
const result = await fetch({
|
|
81
96
|
path: `/runtime/invocation/next`,
|
|
@@ -130,18 +145,7 @@ while (true) {
|
|
|
130
145
|
try {
|
|
131
146
|
response = await fn(request, context);
|
|
132
147
|
} catch (ex) {
|
|
133
|
-
|
|
134
|
-
path: `/runtime/invocation/${context.awsRequestId}/error`,
|
|
135
|
-
method: "POST",
|
|
136
|
-
headers: {
|
|
137
|
-
"Content-Type": "application/json"
|
|
138
|
-
},
|
|
139
|
-
body: JSON.stringify({
|
|
140
|
-
errorType: "Error",
|
|
141
|
-
errorMessage: ex.message,
|
|
142
|
-
trace: ex.stack?.split("\n")
|
|
143
|
-
})
|
|
144
|
-
});
|
|
148
|
+
error(ex);
|
|
145
149
|
continue;
|
|
146
150
|
}
|
|
147
151
|
while (true) {
|