sst 2.22.10 → 2.22.11
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/AstroSite.d.ts +3 -1
- package/constructs/AstroSite.js +4 -0
- package/constructs/Function.js +1 -1
- package/constructs/NextjsSite.d.ts +2 -1
- package/constructs/NextjsSite.js +11 -15
- package/constructs/SsrSite.d.ts +7 -0
- package/constructs/SsrSite.js +4 -1
- package/package.json +1 -1
- package/runtime/handlers/node.js +3 -0
- package/sst.mjs +3 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { SsrSite } from "./SsrSite.js";
|
|
1
|
+
import { SsrSite, SsrSiteProps } from "./SsrSite.js";
|
|
2
2
|
import { SsrFunction } from "./SsrFunction.js";
|
|
3
3
|
import { EdgeFunction } from "./EdgeFunction.js";
|
|
4
|
+
import { Construct } from "constructs";
|
|
4
5
|
/**
|
|
5
6
|
* The `AstroSite` construct is a higher level CDK construct that makes it easy to create a Astro app.
|
|
6
7
|
* @example
|
|
@@ -13,6 +14,7 @@ import { EdgeFunction } from "./EdgeFunction.js";
|
|
|
13
14
|
* ```
|
|
14
15
|
*/
|
|
15
16
|
export declare class AstroSite extends SsrSite {
|
|
17
|
+
constructor(scope: Construct, id: string, props?: Omit<SsrSiteProps, "streaming">);
|
|
16
18
|
protected initBuildConfig(): {
|
|
17
19
|
typesPath: string;
|
|
18
20
|
serverBuildOutputFile: string;
|
package/constructs/AstroSite.js
CHANGED
|
@@ -15,6 +15,10 @@ import { EdgeFunction } from "./EdgeFunction.js";
|
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
17
|
export class AstroSite extends SsrSite {
|
|
18
|
+
constructor(scope, id, props) {
|
|
19
|
+
// Astro apps should always be configured for streaming
|
|
20
|
+
super(scope, props?.cdk?.id || id, { ...props, streaming: true });
|
|
21
|
+
}
|
|
18
22
|
initBuildConfig() {
|
|
19
23
|
return {
|
|
20
24
|
typesPath: "src",
|
package/constructs/Function.js
CHANGED
|
@@ -152,7 +152,7 @@ export class Function extends CDKFunction {
|
|
|
152
152
|
layers: undefined,
|
|
153
153
|
}
|
|
154
154
|
: {
|
|
155
|
-
runtime: CDKRuntime.
|
|
155
|
+
runtime: CDKRuntime.NODEJS_18_X,
|
|
156
156
|
code: Code.fromAsset(path.resolve(__dirname, "../support/bridge")),
|
|
157
157
|
handler: "bridge.handler",
|
|
158
158
|
layers: [],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Construct } from "constructs";
|
|
2
2
|
import { FunctionProps } from "aws-cdk-lib/aws-lambda";
|
|
3
|
-
import { Distribution } from "aws-cdk-lib/aws-cloudfront";
|
|
3
|
+
import { Distribution, CachePolicy } from "aws-cdk-lib/aws-cloudfront";
|
|
4
4
|
import { SsrFunction } from "./SsrFunction.js";
|
|
5
5
|
import { EdgeFunction } from "./EdgeFunction.js";
|
|
6
6
|
import { SsrSite, SsrSiteProps } from "./SsrSite.js";
|
|
@@ -60,6 +60,7 @@ export declare class NextjsSite extends SsrSite {
|
|
|
60
60
|
protected createFunctionForEdge(): EdgeFunction;
|
|
61
61
|
private createImageOptimizationFunction;
|
|
62
62
|
private createWarmer;
|
|
63
|
+
protected buildServerCachePolicy(): CachePolicy;
|
|
63
64
|
protected createCloudFrontDistributionForRegional(): Distribution;
|
|
64
65
|
protected createCloudFrontDistributionForEdge(): Distribution;
|
|
65
66
|
private buildImageBehavior;
|
package/constructs/NextjsSite.js
CHANGED
|
@@ -202,6 +202,15 @@ export class NextjsSite extends SsrSite {
|
|
|
202
202
|
});
|
|
203
203
|
resource.node.addDependency(policy);
|
|
204
204
|
}
|
|
205
|
+
buildServerCachePolicy() {
|
|
206
|
+
return super.buildServerCachePolicy([
|
|
207
|
+
"accept",
|
|
208
|
+
"rsc",
|
|
209
|
+
"next-router-prefetch",
|
|
210
|
+
"next-router-state-tree",
|
|
211
|
+
"next-url",
|
|
212
|
+
]);
|
|
213
|
+
}
|
|
205
214
|
createCloudFrontDistributionForRegional() {
|
|
206
215
|
/**
|
|
207
216
|
* Next.js requests
|
|
@@ -254,14 +263,7 @@ export class NextjsSite extends SsrSite {
|
|
|
254
263
|
*/
|
|
255
264
|
const { cdk } = this.props;
|
|
256
265
|
const cfDistributionProps = cdk?.distribution || {};
|
|
257
|
-
const cachePolicy = cdk?.serverCachePolicy ??
|
|
258
|
-
this.buildServerCachePolicy([
|
|
259
|
-
"accept",
|
|
260
|
-
"rsc",
|
|
261
|
-
"next-router-prefetch",
|
|
262
|
-
"next-router-state-tree",
|
|
263
|
-
"next-url",
|
|
264
|
-
]);
|
|
266
|
+
const cachePolicy = cdk?.serverCachePolicy ?? this.buildServerCachePolicy();
|
|
265
267
|
const serverBehavior = this.buildDefaultBehaviorForRegional(cachePolicy);
|
|
266
268
|
return new Distribution(this, "Distribution", {
|
|
267
269
|
// these values can be overwritten by cfDistributionProps
|
|
@@ -283,13 +285,7 @@ export class NextjsSite extends SsrSite {
|
|
|
283
285
|
createCloudFrontDistributionForEdge() {
|
|
284
286
|
const { cdk } = this.props;
|
|
285
287
|
const cfDistributionProps = cdk?.distribution || {};
|
|
286
|
-
const cachePolicy = cdk?.serverCachePolicy ??
|
|
287
|
-
this.buildServerCachePolicy([
|
|
288
|
-
"accept",
|
|
289
|
-
"rsc",
|
|
290
|
-
"next-router-prefetch",
|
|
291
|
-
"next-router-state-tree",
|
|
292
|
-
]);
|
|
288
|
+
const cachePolicy = cdk?.serverCachePolicy ?? this.buildServerCachePolicy();
|
|
293
289
|
const serverBehavior = this.buildDefaultBehaviorForEdge(cachePolicy);
|
|
294
290
|
return new Distribution(this, "Distribution", {
|
|
295
291
|
// these values can be overwritten by cfDistributionProps
|
package/constructs/SsrSite.d.ts
CHANGED
|
@@ -248,6 +248,12 @@ export interface SsrSiteProps {
|
|
|
248
248
|
* ```
|
|
249
249
|
*/
|
|
250
250
|
fileOptions?: SsrSiteFileOptions[];
|
|
251
|
+
/**
|
|
252
|
+
* The SSR function url supports streaming.
|
|
253
|
+
* [Read more](https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html#config-rs-invoke-furls).
|
|
254
|
+
* @default false
|
|
255
|
+
*/
|
|
256
|
+
streaming?: boolean;
|
|
251
257
|
}
|
|
252
258
|
type SsrSiteNormalizedProps = SsrSiteProps & {
|
|
253
259
|
path: Exclude<SsrSiteProps["path"], undefined>;
|
|
@@ -282,6 +288,7 @@ export declare abstract class SsrSite extends Construct implements SSTConstruct
|
|
|
282
288
|
private distribution;
|
|
283
289
|
private hostedZone?;
|
|
284
290
|
private certificate?;
|
|
291
|
+
private streaming?;
|
|
285
292
|
constructor(scope: Construct, id: string, props?: SsrSiteProps);
|
|
286
293
|
/**
|
|
287
294
|
* The CloudFront URL of the website.
|
package/constructs/SsrSite.js
CHANGED
|
@@ -9,7 +9,7 @@ import { Construct } from "constructs";
|
|
|
9
9
|
import { Fn, Token, Duration as CdkDuration, RemovalPolicy, CustomResource, } from "aws-cdk-lib/core";
|
|
10
10
|
import { BlockPublicAccess, Bucket, } from "aws-cdk-lib/aws-s3";
|
|
11
11
|
import { Role, Effect, Policy, PolicyStatement, AccountPrincipal, ServicePrincipal, CompositePrincipal, } from "aws-cdk-lib/aws-iam";
|
|
12
|
-
import { Function as CdkFunction, Code, Runtime, FunctionUrlAuthType, } from "aws-cdk-lib/aws-lambda";
|
|
12
|
+
import { Function as CdkFunction, Code, Runtime, FunctionUrlAuthType, InvokeMode, } from "aws-cdk-lib/aws-lambda";
|
|
13
13
|
import { HostedZone, ARecord, AaaaRecord, RecordTarget, } from "aws-cdk-lib/aws-route53";
|
|
14
14
|
import { Asset } from "aws-cdk-lib/aws-s3-assets";
|
|
15
15
|
import { Distribution, ViewerProtocolPolicy, AllowedMethods, CachedMethods, LambdaEdgeEventType, CachePolicy, CacheQueryStringBehavior, CacheHeaderBehavior, CacheCookieBehavior, OriginRequestPolicy, Function as CfFunction, FunctionCode as CfFunctionCode, FunctionEventType as CfFunctionEventType, } from "aws-cdk-lib/aws-cloudfront";
|
|
@@ -57,6 +57,7 @@ export class SsrSite extends Construct {
|
|
|
57
57
|
distribution;
|
|
58
58
|
hostedZone;
|
|
59
59
|
certificate;
|
|
60
|
+
streaming;
|
|
60
61
|
constructor(scope, id, props) {
|
|
61
62
|
super(scope, props?.cdk?.id || id);
|
|
62
63
|
const app = scope.node.root;
|
|
@@ -72,6 +73,7 @@ export class SsrSite extends Construct {
|
|
|
72
73
|
};
|
|
73
74
|
this.doNotDeploy =
|
|
74
75
|
!stack.isActive || (app.mode === "dev" && !this.props.dev?.deploy);
|
|
76
|
+
this.streaming = props?.streaming ?? false;
|
|
75
77
|
this.buildConfig = this.initBuildConfig();
|
|
76
78
|
this.validateSiteExists();
|
|
77
79
|
this.validateTimeout();
|
|
@@ -582,6 +584,7 @@ function handler(event) {
|
|
|
582
584
|
const cfDistributionProps = cdk?.distribution || {};
|
|
583
585
|
const fnUrl = this.serverLambdaForRegional.addFunctionUrl({
|
|
584
586
|
authType: FunctionUrlAuthType.NONE,
|
|
587
|
+
invokeMode: this.streaming ? InvokeMode.RESPONSE_STREAM : undefined,
|
|
585
588
|
});
|
|
586
589
|
return {
|
|
587
590
|
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
package/package.json
CHANGED
package/runtime/handlers/node.js
CHANGED
|
@@ -225,6 +225,9 @@ export const useNodeHandler = Context.memo(async () => {
|
|
|
225
225
|
if (input.mode === "start") {
|
|
226
226
|
rebuildCache[input.functionID] = { ctx, result };
|
|
227
227
|
}
|
|
228
|
+
if (input.mode === "deploy") {
|
|
229
|
+
ctx.dispose();
|
|
230
|
+
}
|
|
228
231
|
logMemoryUsage(input.functionID, input.props.handler);
|
|
229
232
|
return {
|
|
230
233
|
type: "success",
|
package/sst.mjs
CHANGED
|
@@ -4702,6 +4702,9 @@ var init_node = __esm({
|
|
|
4702
4702
|
if (input.mode === "start") {
|
|
4703
4703
|
rebuildCache[input.functionID] = { ctx, result };
|
|
4704
4704
|
}
|
|
4705
|
+
if (input.mode === "deploy") {
|
|
4706
|
+
ctx.dispose();
|
|
4707
|
+
}
|
|
4705
4708
|
logMemoryUsage(input.functionID, input.props.handler);
|
|
4706
4709
|
return {
|
|
4707
4710
|
type: "success",
|