sst 2.26.2 → 2.26.4
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/cli/commands/types.js +3 -7
- package/constructs/Api.js +2 -0
- package/constructs/ApiGatewayV1Api.js +2 -0
- package/constructs/App.d.ts +3 -1
- package/constructs/App.js +63 -62
- package/constructs/AppSyncApi.js +2 -0
- package/constructs/AstroSite.d.ts +50 -11
- package/constructs/AstroSite.js +69 -51
- package/constructs/Auth.js +2 -0
- package/constructs/Bucket.js +2 -0
- package/constructs/Cognito.js +2 -0
- package/constructs/Cron.js +2 -0
- package/constructs/EdgeFunction.d.ts +3 -4
- package/constructs/EdgeFunction.js +13 -9
- package/constructs/EventBus.js +2 -0
- package/constructs/Function.d.ts +5 -1
- package/constructs/Function.js +8 -6
- package/constructs/Job.js +3 -3
- package/constructs/KinesisStream.js +2 -0
- package/constructs/NextjsSite.d.ts +84 -22
- package/constructs/NextjsSite.js +150 -254
- package/constructs/Parameter.js +2 -0
- package/constructs/Queue.js +2 -0
- package/constructs/RDS.js +5 -4
- package/constructs/RemixSite.d.ts +65 -11
- package/constructs/RemixSite.js +112 -71
- package/constructs/Script.js +2 -0
- package/constructs/Secret.js +2 -0
- package/constructs/Service.js +4 -3
- package/constructs/SolidStartSite.d.ts +48 -9
- package/constructs/SolidStartSite.js +68 -40
- package/constructs/SsrFunction.d.ts +4 -5
- package/constructs/SsrFunction.js +18 -13
- package/constructs/SsrSite.d.ts +74 -68
- package/constructs/SsrSite.js +657 -682
- package/constructs/StaticSite.js +2 -0
- package/constructs/SvelteKitSite.d.ts +80 -12
- package/constructs/SvelteKitSite.js +90 -64
- package/constructs/Table.js +2 -0
- package/constructs/Topic.js +2 -0
- package/constructs/WebSocketApi.js +2 -0
- package/constructs/deprecated/NextjsSite.js +1 -0
- package/constructs/future/Auth.js +1 -0
- package/package.json +1 -1
- package/support/remix-site-function/edge-server.js +2 -4
- package/support/remix-site-function/regional-server.js +2 -4
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { SsrSite } from "./SsrSite.js";
|
|
2
|
-
import { SsrFunction } from "./SsrFunction.js";
|
|
3
|
-
import { EdgeFunction } from "./EdgeFunction.js";
|
|
4
2
|
/**
|
|
5
3
|
* The `RemixSite` construct is a higher level CDK construct that makes it easy to create a Remix app.
|
|
6
4
|
*
|
|
@@ -15,17 +13,73 @@ import { EdgeFunction } from "./EdgeFunction.js";
|
|
|
15
13
|
* ```
|
|
16
14
|
*/
|
|
17
15
|
export declare class RemixSite extends SsrSite {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
protected plan(): {
|
|
17
|
+
cloudFrontFunctions?: {
|
|
18
|
+
serverCfFunction: {
|
|
19
|
+
constructId: string;
|
|
20
|
+
injections: string[];
|
|
21
|
+
};
|
|
22
|
+
staticCfFunction: {
|
|
23
|
+
constructId: string;
|
|
24
|
+
injections: string[];
|
|
25
|
+
};
|
|
26
|
+
} | undefined;
|
|
27
|
+
edgeFunctions?: {
|
|
28
|
+
edgeServer: {
|
|
29
|
+
constructId: string;
|
|
30
|
+
function: {
|
|
31
|
+
description: string;
|
|
32
|
+
handler: string;
|
|
33
|
+
format: "esm" | "cjs";
|
|
34
|
+
nodejs: {
|
|
35
|
+
esbuild: {
|
|
36
|
+
inject: string[];
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
scopeOverride: RemixSite;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
} | undefined;
|
|
43
|
+
origins: {
|
|
44
|
+
s3: {
|
|
45
|
+
type: "s3";
|
|
46
|
+
copy: {
|
|
47
|
+
from: string;
|
|
48
|
+
to: string;
|
|
49
|
+
cached: true;
|
|
50
|
+
versionedSubDir: string;
|
|
51
|
+
}[];
|
|
52
|
+
};
|
|
53
|
+
regionalServer?: {
|
|
54
|
+
type: "function";
|
|
55
|
+
constructId: string;
|
|
56
|
+
function: {
|
|
57
|
+
description: string;
|
|
58
|
+
handler: string;
|
|
59
|
+
format: "esm" | "cjs";
|
|
60
|
+
nodejs: {
|
|
61
|
+
esbuild: {
|
|
62
|
+
inject: string[];
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
} | undefined;
|
|
67
|
+
};
|
|
68
|
+
behaviors: {
|
|
69
|
+
cacheType: "server" | "static";
|
|
70
|
+
pattern?: string | undefined;
|
|
71
|
+
origin: "s3" | "regionalServer";
|
|
72
|
+
cfFunction?: "serverCfFunction" | "staticCfFunction" | undefined;
|
|
73
|
+
edgeFunction?: "edgeServer" | undefined;
|
|
74
|
+
}[];
|
|
75
|
+
cachePolicyAllowedHeaders?: string[] | undefined;
|
|
76
|
+
buildId?: string | undefined;
|
|
77
|
+
warmerConfig?: {
|
|
78
|
+
function: string;
|
|
79
|
+
} | undefined;
|
|
25
80
|
};
|
|
81
|
+
protected getServerModuleFormat(): "cjs" | "esm";
|
|
26
82
|
private createServerLambdaBundle;
|
|
27
|
-
protected createFunctionForRegional(): SsrFunction;
|
|
28
|
-
protected createFunctionForEdge(): EdgeFunction;
|
|
29
83
|
getConstructMetadata(): {
|
|
30
84
|
data: {
|
|
31
85
|
mode: "placeholder" | "deployed";
|
package/constructs/RemixSite.js
CHANGED
|
@@ -4,8 +4,6 @@ import path from "path";
|
|
|
4
4
|
import { createRequire } from "module";
|
|
5
5
|
const require = createRequire(import.meta.url);
|
|
6
6
|
import { SsrSite } from "./SsrSite.js";
|
|
7
|
-
import { SsrFunction } from "./SsrFunction.js";
|
|
8
|
-
import { EdgeFunction } from "./EdgeFunction.js";
|
|
9
7
|
import { VisibleError } from "../error.js";
|
|
10
8
|
import { useWarning } from "./util/warning.js";
|
|
11
9
|
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
|
@@ -23,27 +21,127 @@ const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
|
|
23
21
|
* ```
|
|
24
22
|
*/
|
|
25
23
|
export class RemixSite extends SsrSite {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
plan() {
|
|
25
|
+
const { path: sitePath, edge } = this.props;
|
|
26
|
+
const { handler, inject } = this.createServerLambdaBundle(edge ? "edge-server.js" : "regional-server.js");
|
|
27
|
+
const format = this.getServerModuleFormat();
|
|
28
|
+
const serverConfig = {
|
|
29
|
+
description: "Server handler for Remix",
|
|
30
|
+
handler,
|
|
31
|
+
format,
|
|
32
|
+
nodejs: {
|
|
33
|
+
esbuild: {
|
|
34
|
+
inject,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
34
37
|
};
|
|
38
|
+
return this.validatePlan({
|
|
39
|
+
cloudFrontFunctions: {
|
|
40
|
+
serverCfFunction: {
|
|
41
|
+
constructId: "CloudFrontFunction",
|
|
42
|
+
injections: [this.useCloudFrontFunctionHostHeaderInjection()],
|
|
43
|
+
},
|
|
44
|
+
staticCfFunction: {
|
|
45
|
+
constructId: "CloudFrontFunctionForStaticBehavior",
|
|
46
|
+
injections: [
|
|
47
|
+
// Note: When using libraries like remix-flat-routes the file can
|
|
48
|
+
// contains special characters like "+". It needs to be encoded.
|
|
49
|
+
`request.uri = request.uri.split('/').map(encodeURIComponent).join('/');`,
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
edgeFunctions: edge
|
|
54
|
+
? {
|
|
55
|
+
edgeServer: {
|
|
56
|
+
constructId: "Server",
|
|
57
|
+
function: {
|
|
58
|
+
scopeOverride: this,
|
|
59
|
+
...serverConfig,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
: undefined,
|
|
64
|
+
origins: {
|
|
65
|
+
...(edge
|
|
66
|
+
? {}
|
|
67
|
+
: {
|
|
68
|
+
regionalServer: {
|
|
69
|
+
type: "function",
|
|
70
|
+
constructId: "ServerFunction",
|
|
71
|
+
function: serverConfig,
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
s3: {
|
|
75
|
+
type: "s3",
|
|
76
|
+
copy: [
|
|
77
|
+
{
|
|
78
|
+
from: "public",
|
|
79
|
+
to: "",
|
|
80
|
+
cached: true,
|
|
81
|
+
versionedSubDir: "build",
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
behaviors: [
|
|
87
|
+
edge
|
|
88
|
+
? {
|
|
89
|
+
cacheType: "server",
|
|
90
|
+
cfFunction: "serverCfFunction",
|
|
91
|
+
edgeFunction: "edgeServer",
|
|
92
|
+
origin: "s3",
|
|
93
|
+
}
|
|
94
|
+
: {
|
|
95
|
+
cacheType: "server",
|
|
96
|
+
cfFunction: "serverCfFunction",
|
|
97
|
+
origin: "regionalServer",
|
|
98
|
+
},
|
|
99
|
+
// create 1 behaviour for each top level asset file/folder
|
|
100
|
+
...fs.readdirSync(path.join(sitePath, "public")).map((item) => ({
|
|
101
|
+
cacheType: "static",
|
|
102
|
+
pattern: fs
|
|
103
|
+
.statSync(path.join(sitePath, "public", item))
|
|
104
|
+
.isDirectory()
|
|
105
|
+
? `${item}/*`
|
|
106
|
+
: item,
|
|
107
|
+
cfFunction: "staticCfFunction",
|
|
108
|
+
origin: "s3",
|
|
109
|
+
})),
|
|
110
|
+
],
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
getServerModuleFormat() {
|
|
114
|
+
const { path: sitePath } = this.props;
|
|
35
115
|
// Validate config path
|
|
36
116
|
const configPath = path.resolve(sitePath, "remix.config.js");
|
|
37
117
|
if (!fs.existsSync(configPath)) {
|
|
38
118
|
throw new VisibleError(`In the "${this.node.id}" Site, could not find "remix.config.js" at expected path "${configPath}".`);
|
|
39
119
|
}
|
|
40
120
|
// Load config
|
|
41
|
-
|
|
42
|
-
|
|
121
|
+
// note: we try to handle Remix v1 and v2
|
|
122
|
+
// - In v1, the config is in CJS by default (ie. module.exports = { ... })
|
|
123
|
+
// and the config can be `require`d directly. We will determine the server
|
|
124
|
+
// format based on "serverModuleFormat" in the config.
|
|
125
|
+
// - In v2, the config is in ESM by default (ie. export default { ... })
|
|
126
|
+
// and we will assume the server format to be ESM.
|
|
127
|
+
let userConfig;
|
|
128
|
+
try {
|
|
129
|
+
userConfig = require(configPath);
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
return "esm";
|
|
133
|
+
}
|
|
134
|
+
const format = userConfig.serverModuleFormat ?? "cjs";
|
|
43
135
|
if (userConfig.serverModuleFormat !== "esm") {
|
|
44
136
|
useWarning().add("remix.cjs");
|
|
45
137
|
}
|
|
46
138
|
// Validate config
|
|
139
|
+
const configDefaults = {
|
|
140
|
+
assetsBuildDirectory: "public/build",
|
|
141
|
+
publicPath: "/build/",
|
|
142
|
+
serverBuildPath: "build/index.js",
|
|
143
|
+
serverPlatform: "node",
|
|
144
|
+
};
|
|
47
145
|
const config = {
|
|
48
146
|
...configDefaults,
|
|
49
147
|
...userConfig,
|
|
@@ -54,17 +152,7 @@ export class RemixSite extends SsrSite {
|
|
|
54
152
|
throw new VisibleError(`In the "${this.node.id}" Site, remix.config.js "${key}" must be "${configDefaults[k]}".`);
|
|
55
153
|
}
|
|
56
154
|
});
|
|
57
|
-
return
|
|
58
|
-
typesPath: ".",
|
|
59
|
-
serverBuildOutputFile: "build/index.js",
|
|
60
|
-
clientBuildOutputDir: "public",
|
|
61
|
-
clientBuildVersionedSubDir: "build",
|
|
62
|
-
// Note: When using libraries like remix-flat-routes the file can
|
|
63
|
-
// contains special characters like "+". It needs to be encoded.
|
|
64
|
-
clientCFFunctionInjection: `
|
|
65
|
-
request.uri = request.uri.split('/').map(encodeURIComponent).join('/');
|
|
66
|
-
`,
|
|
67
|
-
};
|
|
155
|
+
return format;
|
|
68
156
|
}
|
|
69
157
|
createServerLambdaBundle(wrapperFile) {
|
|
70
158
|
// Create a Lambda@Edge handler for the Remix server bundle.
|
|
@@ -99,56 +187,9 @@ export class RemixSite extends SsrSite {
|
|
|
99
187
|
fs.copyFileSync(path.resolve(__dirname, "../support/remix-site-function/polyfill.js"), polyfillDest);
|
|
100
188
|
return {
|
|
101
189
|
handler: path.join(buildPath, "server.handler"),
|
|
102
|
-
|
|
190
|
+
inject: [polyfillDest],
|
|
103
191
|
};
|
|
104
192
|
}
|
|
105
|
-
createFunctionForRegional() {
|
|
106
|
-
const { runtime, timeout, memorySize, permissions, environment, bind, nodejs, cdk, } = this.props;
|
|
107
|
-
const { handler, esbuild } = this.createServerLambdaBundle("regional-server.js");
|
|
108
|
-
return new SsrFunction(this, `ServerFunction`, {
|
|
109
|
-
description: "Server handler for Remix",
|
|
110
|
-
handler,
|
|
111
|
-
runtime,
|
|
112
|
-
memorySize,
|
|
113
|
-
timeout,
|
|
114
|
-
nodejs: {
|
|
115
|
-
format: this.serverModuleFormat,
|
|
116
|
-
...nodejs,
|
|
117
|
-
esbuild: {
|
|
118
|
-
...esbuild,
|
|
119
|
-
...nodejs?.esbuild,
|
|
120
|
-
inject: [...(nodejs?.esbuild?.inject || []), ...esbuild.inject],
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
bind,
|
|
124
|
-
environment,
|
|
125
|
-
permissions,
|
|
126
|
-
...cdk?.server,
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
createFunctionForEdge() {
|
|
130
|
-
const { runtime, timeout, memorySize, bind, permissions, environment, nodejs, } = this.props;
|
|
131
|
-
const { handler, esbuild } = this.createServerLambdaBundle("edge-server.js");
|
|
132
|
-
return new EdgeFunction(this, `Server`, {
|
|
133
|
-
scopeOverride: this,
|
|
134
|
-
handler,
|
|
135
|
-
runtime,
|
|
136
|
-
timeout,
|
|
137
|
-
memorySize,
|
|
138
|
-
bind,
|
|
139
|
-
environment,
|
|
140
|
-
permissions,
|
|
141
|
-
nodejs: {
|
|
142
|
-
format: this.serverModuleFormat,
|
|
143
|
-
...nodejs,
|
|
144
|
-
esbuild: {
|
|
145
|
-
...esbuild,
|
|
146
|
-
...nodejs?.esbuild,
|
|
147
|
-
inject: [...(nodejs?.esbuild?.inject || []), ...esbuild.inject],
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
193
|
getConstructMetadata() {
|
|
153
194
|
return {
|
|
154
195
|
type: "RemixSite",
|
package/constructs/Script.js
CHANGED
|
@@ -58,6 +58,8 @@ export class Script extends Construct {
|
|
|
58
58
|
this.deleteFunction = this.createUserFunction("onDelete", props.onDelete);
|
|
59
59
|
const crFunction = this.createCustomResourceFunction();
|
|
60
60
|
this.createCustomResource(root, crFunction);
|
|
61
|
+
const app = this.node.root;
|
|
62
|
+
app.registerTypes(this);
|
|
61
63
|
}
|
|
62
64
|
/**
|
|
63
65
|
* Binds additional resources to the script
|
package/constructs/Secret.js
CHANGED
package/constructs/Service.js
CHANGED
|
@@ -172,6 +172,7 @@ export class Service extends Construct {
|
|
|
172
172
|
// @ts-expect-error
|
|
173
173
|
this.distribution = null;
|
|
174
174
|
this.devFunction = this.createDevFunction();
|
|
175
|
+
app.registerTypes(this);
|
|
175
176
|
return;
|
|
176
177
|
}
|
|
177
178
|
// Create ECS cluster
|
|
@@ -212,6 +213,7 @@ export class Service extends Construct {
|
|
|
212
213
|
// Invalidate CloudFront
|
|
213
214
|
this.distribution?.createInvalidation();
|
|
214
215
|
});
|
|
216
|
+
app.registerTypes(this);
|
|
215
217
|
}
|
|
216
218
|
/////////////////////
|
|
217
219
|
// Public Properties
|
|
@@ -520,7 +522,7 @@ export class Service extends Construct {
|
|
|
520
522
|
assumedBy: new CompositePrincipal(new AccountPrincipal(app.account), new ServicePrincipal("lambda.amazonaws.com")),
|
|
521
523
|
maxSessionDuration: CdkDuration.hours(12),
|
|
522
524
|
});
|
|
523
|
-
|
|
525
|
+
return new Function(this, `ServerFunction`, {
|
|
524
526
|
description: "Service dev function",
|
|
525
527
|
handler: path.join(__dirname, "../support/service-dev-function", "index.handler"),
|
|
526
528
|
runtime: "nodejs18.x",
|
|
@@ -530,9 +532,8 @@ export class Service extends Construct {
|
|
|
530
532
|
bind,
|
|
531
533
|
environment,
|
|
532
534
|
permissions,
|
|
535
|
+
_doNotAllowOthersToBind: true,
|
|
533
536
|
});
|
|
534
|
-
fn._doNotAllowOthersToBind = true;
|
|
535
|
-
return fn;
|
|
536
537
|
}
|
|
537
538
|
bindForService(constructs) {
|
|
538
539
|
// Get referenced secrets
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { SsrSite } from "./SsrSite.js";
|
|
2
|
-
import { SsrFunction } from "./SsrFunction.js";
|
|
3
|
-
import { EdgeFunction } from "./EdgeFunction.js";
|
|
4
2
|
/**
|
|
5
3
|
* The `SolidStartSite` construct is a higher level CDK construct that makes it easy to create a SolidStart app.
|
|
6
4
|
* @example
|
|
@@ -13,14 +11,55 @@ import { EdgeFunction } from "./EdgeFunction.js";
|
|
|
13
11
|
* ```
|
|
14
12
|
*/
|
|
15
13
|
export declare class SolidStartSite extends SsrSite {
|
|
16
|
-
protected
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
protected plan(): {
|
|
15
|
+
cloudFrontFunctions?: {
|
|
16
|
+
serverCfFunction: {
|
|
17
|
+
constructId: string;
|
|
18
|
+
injections: string[];
|
|
19
|
+
};
|
|
20
|
+
} | undefined;
|
|
21
|
+
edgeFunctions?: {
|
|
22
|
+
edgeServer: {
|
|
23
|
+
constructId: string;
|
|
24
|
+
function: {
|
|
25
|
+
description: string;
|
|
26
|
+
handler: string;
|
|
27
|
+
scopeOverride: SolidStartSite;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
} | undefined;
|
|
31
|
+
origins: {
|
|
32
|
+
s3: {
|
|
33
|
+
type: "s3";
|
|
34
|
+
copy: {
|
|
35
|
+
from: string;
|
|
36
|
+
to: string;
|
|
37
|
+
cached: true;
|
|
38
|
+
versionedSubDir: string;
|
|
39
|
+
}[];
|
|
40
|
+
};
|
|
41
|
+
regionalServer?: {
|
|
42
|
+
type: "function";
|
|
43
|
+
constructId: string;
|
|
44
|
+
function: {
|
|
45
|
+
description: string;
|
|
46
|
+
handler: string;
|
|
47
|
+
};
|
|
48
|
+
} | undefined;
|
|
49
|
+
};
|
|
50
|
+
behaviors: {
|
|
51
|
+
cacheType: "server" | "static";
|
|
52
|
+
pattern?: string | undefined;
|
|
53
|
+
origin: "s3" | "regionalServer";
|
|
54
|
+
cfFunction?: "serverCfFunction" | undefined;
|
|
55
|
+
edgeFunction?: "edgeServer" | undefined;
|
|
56
|
+
}[];
|
|
57
|
+
cachePolicyAllowedHeaders?: string[] | undefined;
|
|
58
|
+
buildId?: string | undefined;
|
|
59
|
+
warmerConfig?: {
|
|
60
|
+
function: string;
|
|
61
|
+
} | undefined;
|
|
21
62
|
};
|
|
22
|
-
protected createFunctionForRegional(): SsrFunction;
|
|
23
|
-
protected createFunctionForEdge(): EdgeFunction;
|
|
24
63
|
getConstructMetadata(): {
|
|
25
64
|
data: {
|
|
26
65
|
mode: "placeholder" | "deployed";
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import fs from "fs";
|
|
1
2
|
import path from "path";
|
|
2
3
|
import { SsrSite } from "./SsrSite.js";
|
|
3
|
-
import { SsrFunction } from "./SsrFunction.js";
|
|
4
|
-
import { EdgeFunction } from "./EdgeFunction.js";
|
|
5
4
|
/**
|
|
6
5
|
* The `SolidStartSite` construct is a higher level CDK construct that makes it easy to create a SolidStart app.
|
|
7
6
|
* @example
|
|
@@ -14,47 +13,76 @@ import { EdgeFunction } from "./EdgeFunction.js";
|
|
|
14
13
|
* ```
|
|
15
14
|
*/
|
|
16
15
|
export class SolidStartSite extends SsrSite {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
serverBuildOutputFile: "dist/server/index.mjs",
|
|
21
|
-
clientBuildOutputDir: "dist/client",
|
|
22
|
-
clientBuildVersionedSubDir: "assets",
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
createFunctionForRegional() {
|
|
26
|
-
const { runtime, timeout, memorySize, bind, nodejs, permissions, environment, cdk, } = this.props;
|
|
27
|
-
return new SsrFunction(this, `ServerFunction`, {
|
|
16
|
+
plan() {
|
|
17
|
+
const { path: sitePath, edge } = this.props;
|
|
18
|
+
const serverConfig = {
|
|
28
19
|
description: "Server handler for Solid",
|
|
29
|
-
handler: path.join(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
handler: path.join(sitePath, "dist", "server", "index.handler"),
|
|
21
|
+
};
|
|
22
|
+
return this.validatePlan({
|
|
23
|
+
cloudFrontFunctions: {
|
|
24
|
+
serverCfFunction: {
|
|
25
|
+
constructId: "CloudFrontFunction",
|
|
26
|
+
injections: [this.useCloudFrontFunctionHostHeaderInjection()],
|
|
27
|
+
},
|
|
36
28
|
},
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
29
|
+
edgeFunctions: edge
|
|
30
|
+
? {
|
|
31
|
+
edgeServer: {
|
|
32
|
+
constructId: "Server",
|
|
33
|
+
function: {
|
|
34
|
+
scopeOverride: this,
|
|
35
|
+
...serverConfig,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
: undefined,
|
|
40
|
+
origins: {
|
|
41
|
+
...(edge
|
|
42
|
+
? {}
|
|
43
|
+
: {
|
|
44
|
+
regionalServer: {
|
|
45
|
+
type: "function",
|
|
46
|
+
constructId: "ServerFunction",
|
|
47
|
+
function: serverConfig,
|
|
48
|
+
},
|
|
49
|
+
}),
|
|
50
|
+
s3: {
|
|
51
|
+
type: "s3",
|
|
52
|
+
copy: [
|
|
53
|
+
{
|
|
54
|
+
from: "dist/client",
|
|
55
|
+
to: "",
|
|
56
|
+
cached: true,
|
|
57
|
+
versionedSubDir: "assets",
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
57
61
|
},
|
|
62
|
+
behaviors: [
|
|
63
|
+
edge
|
|
64
|
+
? {
|
|
65
|
+
cacheType: "server",
|
|
66
|
+
cfFunction: "serverCfFunction",
|
|
67
|
+
edgeFunction: "edgeServer",
|
|
68
|
+
origin: "s3",
|
|
69
|
+
}
|
|
70
|
+
: {
|
|
71
|
+
cacheType: "server",
|
|
72
|
+
cfFunction: "serverCfFunction",
|
|
73
|
+
origin: "regionalServer",
|
|
74
|
+
},
|
|
75
|
+
// create 1 behaviour for each top level asset file/folder
|
|
76
|
+
...fs.readdirSync(path.join(sitePath, "dist/client")).map((item) => ({
|
|
77
|
+
cacheType: "static",
|
|
78
|
+
pattern: fs
|
|
79
|
+
.statSync(path.join(sitePath, "dist/client", item))
|
|
80
|
+
.isDirectory()
|
|
81
|
+
? `${item}/*`
|
|
82
|
+
: item,
|
|
83
|
+
origin: "s3",
|
|
84
|
+
})),
|
|
85
|
+
],
|
|
58
86
|
});
|
|
59
87
|
}
|
|
60
88
|
getConstructMetadata() {
|
|
@@ -11,8 +11,8 @@ export interface SsrFunctionProps extends Omit<FunctionOptions, "memorySize" | "
|
|
|
11
11
|
bundle?: string;
|
|
12
12
|
handler: string;
|
|
13
13
|
runtime?: "nodejs14.x" | "nodejs16.x" | "nodejs18.x";
|
|
14
|
-
timeout
|
|
15
|
-
memorySize
|
|
14
|
+
timeout?: number | Duration;
|
|
15
|
+
memorySize?: number | Size;
|
|
16
16
|
permissions?: Permissions;
|
|
17
17
|
environment?: Record<string, string>;
|
|
18
18
|
bind?: SSTConstruct[];
|
|
@@ -22,12 +22,12 @@ export interface SsrFunctionProps extends Omit<FunctionOptions, "memorySize" | "
|
|
|
22
22
|
}
|
|
23
23
|
export declare class SsrFunction extends Construct implements SSTConstruct {
|
|
24
24
|
readonly id: string;
|
|
25
|
+
/** @internal */
|
|
26
|
+
readonly _doNotAllowOthersToBind = true;
|
|
25
27
|
function: CdkFunction;
|
|
26
28
|
private assetReplacer;
|
|
27
29
|
private assetReplacerPolicy;
|
|
28
30
|
private props;
|
|
29
|
-
/** @internal */
|
|
30
|
-
_doNotAllowOthersToBind: boolean;
|
|
31
31
|
constructor(scope: Construct, id: string, props: SsrFunctionProps);
|
|
32
32
|
get role(): import("aws-cdk-lib/aws-iam").IRole | undefined;
|
|
33
33
|
get functionArn(): string;
|
|
@@ -35,7 +35,6 @@ export declare class SsrFunction extends Construct implements SSTConstruct {
|
|
|
35
35
|
addEnvironment(key: string, value: string): CdkFunction;
|
|
36
36
|
addFunctionUrl(props?: FunctionUrlOptions): import("aws-cdk-lib/aws-lambda").FunctionUrl;
|
|
37
37
|
grantInvoke(grantee: IGrantable): import("aws-cdk-lib/aws-iam").Grant;
|
|
38
|
-
build(): Promise<void>;
|
|
39
38
|
attachPermissions(permissions: Permissions): void;
|
|
40
39
|
private createFunction;
|
|
41
40
|
private createCodeReplacer;
|
|
@@ -15,23 +15,26 @@ import { bindEnvironment, bindPermissions, getReferencedSecrets, } from "./util/
|
|
|
15
15
|
import { attachPermissionsToRole } from "./util/permission.js";
|
|
16
16
|
import { toCdkSize } from "./util/size.js";
|
|
17
17
|
import { toCdkDuration } from "./util/duration.js";
|
|
18
|
+
import { useDeferredTasks } from "./deferred_task.js";
|
|
18
19
|
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
19
20
|
/////////////////////
|
|
20
21
|
// Construct
|
|
21
22
|
/////////////////////
|
|
22
23
|
export class SsrFunction extends Construct {
|
|
23
24
|
id;
|
|
25
|
+
/** @internal */
|
|
26
|
+
_doNotAllowOthersToBind = true;
|
|
24
27
|
function;
|
|
25
28
|
assetReplacer;
|
|
26
29
|
assetReplacerPolicy;
|
|
27
30
|
props;
|
|
28
|
-
/** @internal */
|
|
29
|
-
_doNotAllowOthersToBind = true;
|
|
30
31
|
constructor(scope, id, props) {
|
|
31
32
|
super(scope, id);
|
|
32
33
|
this.id = id;
|
|
33
34
|
this.props = {
|
|
34
35
|
...props,
|
|
36
|
+
timeout: 10,
|
|
37
|
+
memorySize: 1024,
|
|
35
38
|
environment: props.environment || {},
|
|
36
39
|
permissions: props.permissions || [],
|
|
37
40
|
};
|
|
@@ -45,6 +48,19 @@ export class SsrFunction extends Construct {
|
|
|
45
48
|
this.function.node.addDependency(assetReplacer);
|
|
46
49
|
this.assetReplacer = assetReplacer;
|
|
47
50
|
this.assetReplacerPolicy = assetReplacerPolicy;
|
|
51
|
+
useDeferredTasks().add(async () => {
|
|
52
|
+
const { bundle } = props;
|
|
53
|
+
const code = bundle
|
|
54
|
+
? await this.buildAssetFromBundle(bundle)
|
|
55
|
+
: await this.buildAssetFromHandler();
|
|
56
|
+
const codeConfig = code.bind(this.function);
|
|
57
|
+
const assetBucket = codeConfig.s3Location?.bucketName;
|
|
58
|
+
const assetKey = codeConfig.s3Location?.objectKey;
|
|
59
|
+
this.updateCodeReplacer(assetBucket, assetKey);
|
|
60
|
+
this.updateFunction(code, assetBucket, assetKey);
|
|
61
|
+
});
|
|
62
|
+
const app = this.node.root;
|
|
63
|
+
app.registerTypes(this);
|
|
48
64
|
}
|
|
49
65
|
get role() {
|
|
50
66
|
return this.function.role;
|
|
@@ -64,17 +80,6 @@ export class SsrFunction extends Construct {
|
|
|
64
80
|
grantInvoke(grantee) {
|
|
65
81
|
return this.function.grantInvoke(grantee);
|
|
66
82
|
}
|
|
67
|
-
async build() {
|
|
68
|
-
const { bundle, handler } = this.props;
|
|
69
|
-
const code = bundle
|
|
70
|
-
? await this.buildAssetFromBundle(bundle)
|
|
71
|
-
: await this.buildAssetFromHandler();
|
|
72
|
-
const codeConfig = code.bind(this.function);
|
|
73
|
-
const assetBucket = codeConfig.s3Location?.bucketName;
|
|
74
|
-
const assetKey = codeConfig.s3Location?.objectKey;
|
|
75
|
-
this.updateCodeReplacer(assetBucket, assetKey);
|
|
76
|
-
this.updateFunction(code, assetBucket, assetKey);
|
|
77
|
-
}
|
|
78
83
|
attachPermissions(permissions) {
|
|
79
84
|
attachPermissionsToRole(this.function.role, permissions);
|
|
80
85
|
}
|