sst 2.22.9 → 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/project.js +8 -1
- package/runtime/handlers/node.js +3 -0
- package/sst.mjs +5 -1
|
@@ -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/project.js
CHANGED
|
@@ -47,10 +47,17 @@ export async function initProject(globals) {
|
|
|
47
47
|
throw new VisibleError("Could not found a configuration file", "Make sure one of the following exists", ...CONFIG_EXTENSIONS.map((x) => ` - sst${x}`));
|
|
48
48
|
})();
|
|
49
49
|
const config = await Promise.resolve(sstConfig.config(globals));
|
|
50
|
-
const stage =
|
|
50
|
+
const stage = process.env.SST_STAGE ||
|
|
51
|
+
globals.stage ||
|
|
51
52
|
config.stage ||
|
|
52
53
|
(await usePersonalStage(out)) ||
|
|
53
54
|
(await promptPersonalStage(out));
|
|
55
|
+
// Set stage to SST_STAGE so that if SST spawned processes are aware
|
|
56
|
+
// of the stage. ie.
|
|
57
|
+
// `sst deploy --stage prod`: `prod` stage passed in via CLI
|
|
58
|
+
// -> spawns `open-next build`
|
|
59
|
+
// -> spawns `sst bind`: `prod` stage read from SST_STAGE
|
|
60
|
+
process.env.SST_STAGE = stage;
|
|
54
61
|
const [version, cdkVersion, constructsVersion] = await (async () => {
|
|
55
62
|
try {
|
|
56
63
|
const packageJson = JSON.parse(await fs
|
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
|
@@ -381,7 +381,8 @@ async function initProject(globals) {
|
|
|
381
381
|
);
|
|
382
382
|
}();
|
|
383
383
|
const config = await Promise.resolve(sstConfig.config(globals));
|
|
384
|
-
const stage = globals.stage || config.stage || await usePersonalStage(out) || await promptPersonalStage(out);
|
|
384
|
+
const stage = process.env.SST_STAGE || globals.stage || config.stage || await usePersonalStage(out) || await promptPersonalStage(out);
|
|
385
|
+
process.env.SST_STAGE = stage;
|
|
385
386
|
const [version2, cdkVersion, constructsVersion] = await (async () => {
|
|
386
387
|
try {
|
|
387
388
|
const packageJson = JSON.parse(
|
|
@@ -4701,6 +4702,9 @@ var init_node = __esm({
|
|
|
4701
4702
|
if (input.mode === "start") {
|
|
4702
4703
|
rebuildCache[input.functionID] = { ctx, result };
|
|
4703
4704
|
}
|
|
4705
|
+
if (input.mode === "deploy") {
|
|
4706
|
+
ctx.dispose();
|
|
4707
|
+
}
|
|
4704
4708
|
logMemoryUsage(input.functionID, input.props.handler);
|
|
4705
4709
|
return {
|
|
4706
4710
|
type: "success",
|