sst 2.28.1 → 2.28.5

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,4 +1,3 @@
1
- import { lazy } from "../../util/lazy.js";
2
1
  export const dev = (program) => program.command(["dev", "start"], "Work on your app locally", (yargs) => yargs.option("increase-timeout", {
3
2
  type: "boolean",
4
3
  description: "Increase function timeout",
@@ -19,6 +18,8 @@ export const dev = (program) => program.command(["dev", "start"], "Work on your
19
18
  const { useProject } = await import("../../project.js");
20
19
  const { clear } = await import("../terminal.js");
21
20
  const { getCiInfo } = await import("../ci-info.js");
21
+ const { useMetadataCache } = await import("../../stacks/metadata.js");
22
+ const { lazy } = await import("../../util/lazy.js");
22
23
  try {
23
24
  if (args._[0] === "start") {
24
25
  console.log(yellow(`Warning: ${bold(`sst start`)} has been renamed to ${bold(`sst dev`)}`));
@@ -320,6 +321,7 @@ export const dev = (program) => program.command(["dev", "start"], "Work on your
320
321
  await printHeader({ console: true, hint: "ready!" });
321
322
  await Promise.all([
322
323
  useStackBuilder(),
324
+ useMetadataCache(),
323
325
  useDisconnector(),
324
326
  import("../../runtime/workers.js").then((mod) => mod.useRuntimeWorkers()),
325
327
  import("../../runtime/iot.js").then((mod) => mod.useIOTBridge()),
@@ -201,7 +201,7 @@ export interface ApiProps<Authorizers extends Record<string, ApiAuthorizer> = Re
201
201
  */
202
202
  cors?: boolean | ApiCorsProps;
203
203
  /**
204
- * Enable CloudWatch access logs for this API
204
+ * Enable CloudWatch access logs for this API. Defaults to true.
205
205
  *
206
206
  * @default true
207
207
  *
@@ -19,26 +19,6 @@ export class AstroSite extends SsrSite {
19
19
  super(scope, id, {
20
20
  ...props,
21
21
  typesPath: props?.typesPath ?? "src",
22
- fileOptions: props?.fileOptions ?? [
23
- {
24
- exclude: "*",
25
- include: "*.css",
26
- cacheControl: "public,max-age=0,s-maxage=31536000,must-revalidate",
27
- contentType: "text/css; charset=UTF-8",
28
- },
29
- {
30
- exclude: "*",
31
- include: "*.js",
32
- cacheControl: "public,max-age=0,s-maxage=31536000,must-revalidate",
33
- contentType: "application/javascript; charset=UTF-8",
34
- },
35
- {
36
- exclude: "*",
37
- include: "*.html",
38
- cacheControl: "public,max-age=0,s-maxage=31536000,must-revalidate",
39
- contentType: "text/html; charset=UTF-8",
40
- },
41
- ],
42
22
  regional: {
43
23
  ...props?.regional,
44
24
  },
@@ -179,14 +159,28 @@ export class AstroSite extends SsrSite {
179
159
  pattern: route,
180
160
  origin: "regionalServer",
181
161
  })));
182
- const notFoundRoute = buildMeta.routes.find(({ route, type }) => route.match(/^\/404\/?$/) && type === "page");
183
- if (notFoundRoute) {
184
- plan.errorResponses?.push({
185
- httpStatus: 404,
186
- responsePagePath: "/404.html",
187
- responseHttpStatus: 404,
188
- });
189
- }
162
+ buildMeta.routes
163
+ .filter(({ type, route }) => type === "page" && /^\/\d{3}\/?$/.test(route))
164
+ .forEach(({ route, prerender }) => {
165
+ switch (route) {
166
+ case "/404":
167
+ case "/404/":
168
+ plan.errorResponses?.push({
169
+ httpStatus: 404,
170
+ responsePagePath: prerender ? "/404.html" : "/404",
171
+ responseHttpStatus: 404,
172
+ });
173
+ break;
174
+ case "/500":
175
+ case "/500/":
176
+ plan.errorResponses?.push({
177
+ httpStatus: 500,
178
+ responsePagePath: prerender ? "/500.html" : "/500",
179
+ responseHttpStatus: 500,
180
+ });
181
+ break;
182
+ }
183
+ });
190
184
  }
191
185
  return this.validatePlan(plan);
192
186
  }
@@ -99,6 +99,7 @@ type NextjsSiteNormalizedProps = NextjsSiteProps & SsrSiteNormalizedProps;
99
99
  */
100
100
  export declare class NextjsSite extends SsrSite {
101
101
  props: NextjsSiteNormalizedProps;
102
+ private buildId?;
102
103
  constructor(scope: Construct, id: string, props?: NextjsSiteProps);
103
104
  protected plan(bucket: Bucket): {
104
105
  cloudFrontFunctions?: {
@@ -189,7 +190,9 @@ export declare class NextjsSite extends SsrSite {
189
190
  private createRevalidationQueue;
190
191
  private createRevalidationTable;
191
192
  getConstructMetadata(): {
193
+ type: "NextjsSite";
192
194
  data: {
195
+ routes: any[];
193
196
  mode: "placeholder" | "deployed";
194
197
  path: string;
195
198
  runtime: "nodejs14.x" | "nodejs16.x" | "nodejs18.x";
@@ -199,7 +202,9 @@ export declare class NextjsSite extends SsrSite {
199
202
  server: string;
200
203
  secrets: string[];
201
204
  };
202
- type: "NextjsSite";
203
205
  };
206
+ private wrapHandler;
207
+ private getRoutes;
208
+ private useBuildId;
204
209
  }
205
210
  export {};
@@ -11,6 +11,7 @@ import { SsrSite } from "./SsrSite.js";
11
11
  import { toCdkSize } from "./util/size.js";
12
12
  import { PolicyStatement } from "aws-cdk-lib/aws-iam";
13
13
  import { RetentionDays } from "aws-cdk-lib/aws-logs";
14
+ import { VisibleError } from "../error.js";
14
15
  /**
15
16
  * The `NextjsSite` construct is a higher level CDK construct that makes it easy to create a Next.js app.
16
17
  * @example
@@ -23,6 +24,7 @@ import { RetentionDays } from "aws-cdk-lib/aws-logs";
23
24
  * ```
24
25
  */
25
26
  export class NextjsSite extends SsrSite {
27
+ buildId;
26
28
  constructor(scope, id, props) {
27
29
  const { streaming, disableDynamoDBCache, disableIncrementalCache } = {
28
30
  streaming: false,
@@ -32,7 +34,7 @@ export class NextjsSite extends SsrSite {
32
34
  };
33
35
  super(scope, id, {
34
36
  buildCommand: [
35
- "npx --yes open-next@2.2.1 build",
37
+ "npx --yes open-next@2.2.3 build",
36
38
  ...(streaming ? ["--streaming"] : []),
37
39
  ...(disableDynamoDBCache
38
40
  ? ["--dangerously-disable-dynamodb-cache"]
@@ -55,7 +57,7 @@ export class NextjsSite extends SsrSite {
55
57
  const serverConfig = {
56
58
  description: "Next.js server",
57
59
  bundle: path.join(sitePath, ".open-next", "server-function"),
58
- handler: "index.handler",
60
+ handler: this.wrapHandler(),
59
61
  environment: {
60
62
  CACHE_BUCKET_NAME: bucket.bucketName,
61
63
  CACHE_BUCKET_KEY_PREFIX: "_cache",
@@ -189,9 +191,7 @@ export class NextjsSite extends SsrSite {
189
191
  "next-router-state-tree",
190
192
  "next-url",
191
193
  ],
192
- buildId: fs
193
- .readFileSync(path.join(sitePath, ".next/BUILD_ID"))
194
- .toString(),
194
+ buildId: this.useBuildId(),
195
195
  warmerConfig: {
196
196
  function: path.join(sitePath, ".open-next", "warmer-function"),
197
197
  },
@@ -276,9 +276,53 @@ export class NextjsSite extends SsrSite {
276
276
  }
277
277
  }
278
278
  getConstructMetadata() {
279
+ const metadata = this.getConstructMetadataBase();
279
280
  return {
281
+ ...metadata,
280
282
  type: "NextjsSite",
281
- ...this.getConstructMetadataBase(),
283
+ data: {
284
+ ...metadata.data,
285
+ routes: this.getRoutes(),
286
+ },
282
287
  };
283
288
  }
289
+ wrapHandler() {
290
+ const { path: sitePath } = this.props;
291
+ const wrapperName = "nextjssite-index";
292
+ const serverPath = path.join(sitePath, ".open-next", "server-function");
293
+ fs.writeFileSync(path.join(serverPath, `${wrapperName}.mjs`), [
294
+ `import { handler as rawHandler } from "./index.mjs";`,
295
+ `export const handler = (event, context) => {`,
296
+ ` return rawHandler(event, context);`,
297
+ `};`,
298
+ ].join("\n"));
299
+ return `${wrapperName}.handler`;
300
+ }
301
+ getRoutes() {
302
+ const id = this.node.id;
303
+ const { path: sitePath } = this.props;
304
+ try {
305
+ const content = JSON.parse(fs
306
+ .readFileSync(path.join(sitePath, ".next/routes-manifest.json"))
307
+ .toString());
308
+ return [
309
+ ...[...content.dynamicRoutes, ...content.staticRoutes].map(({ page }) => ({
310
+ route: page,
311
+ })),
312
+ ...(content.dataRoutes || []).map(({ page }) => ({
313
+ route: page.endsWith("/")
314
+ ? `/_next/data/${this.useBuildId()}${page}index.json`
315
+ : `/_next/data/${this.useBuildId()}${page}.json`,
316
+ })),
317
+ ];
318
+ }
319
+ catch (e) {
320
+ console.error(e);
321
+ throw new VisibleError(`Failed to read routes data from ".next/routes-manifest.json" for the "${id}" site.`);
322
+ }
323
+ }
324
+ useBuildId() {
325
+ const { path: sitePath } = this.props;
326
+ return fs.readFileSync(path.join(sitePath, ".next/BUILD_ID")).toString();
327
+ }
284
328
  }
@@ -248,7 +248,7 @@ export interface SsrSiteProps {
248
248
  * from the server rendering Lambda.
249
249
  */
250
250
  responseHeadersPolicy?: IResponseHeadersPolicy;
251
- server?: Pick<CdkFunctionProps, "vpc" | "vpcSubnets" | "securityGroups" | "allowAllOutbound" | "allowPublicSubnet" | "architecture" | "logRetention"> & Pick<FunctionProps, "copyFiles">;
251
+ server?: Pick<CdkFunctionProps, "layers" | "vpc" | "vpcSubnets" | "securityGroups" | "allowAllOutbound" | "allowPublicSubnet" | "architecture" | "logRetention"> & Pick<FunctionProps, "copyFiles">;
252
252
  };
253
253
  /**
254
254
  * Pass in a list of file options to customize cache control and content type specific files.
@@ -195,7 +195,7 @@ export class SsrSite extends Construct {
195
195
  bind,
196
196
  environment,
197
197
  permissions,
198
- // note: do not need to set vpc settings b/c this function is not being used
198
+ // note: do not need to set vpc and layers settings b/c this function is not being used
199
199
  });
200
200
  }
201
201
  function createWarmer() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "sst",
4
- "version": "2.28.1",
4
+ "version": "2.28.5",
5
5
  "bin": {
6
6
  "sst": "cli/sst.js"
7
7
  },
@@ -119,7 +119,7 @@
119
119
  "@types/ws": "^8.5.3",
120
120
  "@types/yargs": "^17.0.13",
121
121
  "archiver": "^5.3.1",
122
- "astro-sst": "2.28.1",
122
+ "astro-sst": "2.28.5",
123
123
  "tsx": "^3.12.1",
124
124
  "typescript": "^5.2.2",
125
125
  "vitest": "^0.33.0"