Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
ssr-site: customize cf functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fwang committed Sep 10, 2024
1 parent 6128d74 commit 1e269ad
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 169 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion platform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@aws-sdk/client-ssm": "3.478.0",
"@aws-sdk/client-sts": "3.478.0",
"@aws-sdk/middleware-retry": "3.374.0",
"@pulumi/aws": "6.28.1",
"@pulumi/aws": "6.51.0",
"@pulumi/cloudflare": "5.37.1",
"@pulumi/docker-build": "0.0.6",
"@pulumi/pulumi": "3.115.2",
Expand Down
17 changes: 5 additions & 12 deletions platform/src/components/aws/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ export interface AstroArgs extends SsrSiteArgs {
* To disable dev mode, pass in `false`.
*/
dev?: false | DevArgs["dev"];
/**
* The number of instances of the [server function](#nodes-server) to keep warm. This is useful for cases where you are experiencing long cold starts. The default is to not keep any instances warm.
*
* This works by starting a serverless cron job to make _n_ concurrent requests to the server function every few minutes. Where _n_ is the number of instances to keep warm.
*
* @default `0`
*/
warm?: SsrSiteArgs["warm"];
/**
* Permissions and the resources that the [server function](#nodes-server) in your Astro site needs to access. These permissions are used to create the function's IAM role.
*
Expand Down Expand Up @@ -693,10 +685,11 @@ function useCloudFrontRoutingInjection(buildMetadata: BuildMetaConfig) {
var matchedRoute = findFirstMatch(findMatches(request.uri, routeData));
if (matchedRoute[0]) {
if (!matchedRoute[1] && !/^.*\\.[^\\/]+$/.test(request.uri)) {
${buildMetadata.pageResolution === "file"
? `request.uri = request.uri === "/" ? "/index.html" : request.uri.replace(/\\/?$/, ".html");`
: `request.uri = request.uri.replace(/\\/?$/, "/index.html");`
}
${
buildMetadata.pageResolution === "file"
? `request.uri = request.uri === "/" ? "/index.html" : request.uri.replace(/\\/?$/, ".html");`
: `request.uri = request.uri.replace(/\\/?$/, "/index.html");`
}
} else if (matchedRoute[1] === 2) {
var redirectPath = matchedRoute[2];
matchedRoute[0].exec(request.uri).forEach((match, index) => {
Expand Down
68 changes: 30 additions & 38 deletions platform/src/components/aws/nextjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,6 @@ export interface NextjsArgs extends SsrSiteArgs {
* To disable dev mode, pass in `false`.
*/
dev?: false | DevArgs["dev"];
/**
* The number of instances of the [server function](#nodes-server) to keep warm. This is useful for cases where you are experiencing long cold starts. The default is to not keep any instances warm.
*
* This works by starting a serverless cron job to make _n_ concurrent requests to the server function every few minutes. Where _n_ is the number of instances to keep warm.
*
* @default `0`
*/
warm?: SsrSiteArgs["warm"];
/**
* Permissions and the resources that the [server function](#nodes-server) in your Next.js app needs to access. These permissions are used to create the function's IAM role.
*
Expand Down Expand Up @@ -807,39 +799,39 @@ export class Nextjs extends Component implements Link.Linkable {
},
...(revalidationQueueArn
? [
{
actions: [
"sqs:SendMessage",
"sqs:GetQueueAttributes",
"sqs:GetQueueUrl",
],
resources: [revalidationQueueArn],
},
]
{
actions: [
"sqs:SendMessage",
"sqs:GetQueueAttributes",
"sqs:GetQueueUrl",
],
resources: [revalidationQueueArn],
},
]
: []),
...(revalidationTableArn
? [
{
actions: [
"dynamodb:BatchGetItem",
"dynamodb:GetRecords",
"dynamodb:GetShardIterator",
"dynamodb:Query",
"dynamodb:GetItem",
"dynamodb:Scan",
"dynamodb:ConditionCheckItem",
"dynamodb:BatchWriteItem",
"dynamodb:PutItem",
"dynamodb:UpdateItem",
"dynamodb:DeleteItem",
"dynamodb:DescribeTable",
],
resources: [
revalidationTableArn,
`${revalidationTableArn}/*`,
],
},
]
{
actions: [
"dynamodb:BatchGetItem",
"dynamodb:GetRecords",
"dynamodb:GetShardIterator",
"dynamodb:Query",
"dynamodb:GetItem",
"dynamodb:Scan",
"dynamodb:ConditionCheckItem",
"dynamodb:BatchWriteItem",
"dynamodb:PutItem",
"dynamodb:UpdateItem",
"dynamodb:DeleteItem",
"dynamodb:DescribeTable",
],
resources: [
revalidationTableArn,
`${revalidationTableArn}/*`,
],
},
]
: []),
],
};
Expand Down
8 changes: 0 additions & 8 deletions platform/src/components/aws/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ export interface NuxtArgs extends SsrSiteArgs {
* To disable dev mode, pass in `false`.
*/
dev?: false | DevArgs["dev"];
/**
* The number of instances of the [server function](#nodes-server) to keep warm. This is useful for cases where you are experiencing long cold starts. The default is to not keep any instances warm.
*
* This works by starting a serverless cron job to make _n_ concurrent requests to the server function every few minutes. Where _n_ is the number of instances to keep warm.
*
* @default `0`
*/
warm?: SsrSiteArgs["warm"];
/**
* Permissions and the resources that the [server function](#nodes-server) in your Nuxt app needs to access. These permissions are used to create the function's IAM role.
*
Expand Down
8 changes: 0 additions & 8 deletions platform/src/components/aws/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ export interface ReactArgs extends SsrSiteArgs {
* To disable dev mode, pass in `false`.
*/
dev?: false | DevArgs["dev"];
/**
* The number of instances of the [server function](#nodes-server) to keep warm. This is useful for cases where you are experiencing long cold starts. The default is to not keep any instances warm.
*
* This works by starting a serverless cron job to make _n_ concurrent requests to the server function every few minutes. Where _n_ is the number of instances to keep warm.
*
* @default `0`
*/
warm?: SsrSiteArgs["warm"];
/**
* Permissions and the resources that the [server function](#nodes-server) in your React app needs to access. These permissions are used to create the function's IAM role.
*
Expand Down
42 changes: 17 additions & 25 deletions platform/src/components/aws/remix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ export interface RemixArgs extends SsrSiteArgs {
* To disable dev mode, pass in `false`.
*/
dev?: false | DevArgs["dev"];
/**
* The number of instances of the [server function](#nodes-server) to keep warm. This is useful for cases where you are experiencing long cold starts. The default is to not keep any instances warm.
*
* This works by starting a serverless cron job to make _n_ concurrent requests to the server function every few minutes. Where _n_ is the number of instances to keep warm.
*
* @default `0`
*/
warm?: SsrSiteArgs["warm"];
/**
* Permissions and the resources that the [server function](#nodes-server) in your Remix app needs to access. These permissions are used to create the function's IAM role.
*
Expand Down Expand Up @@ -572,21 +564,21 @@ export class Remix extends Component implements Link.Linkable {
},
edgeFunctions: edge
? {
server: {
function: serverConfig,
},
}
server: {
function: serverConfig,
},
}
: undefined,
origins: {
...(edge
? {}
: {
server: {
server: {
function: serverConfig,
server: {
function: serverConfig,
},
},
},
}),
}),
s3: {
s3: {
copy: [
Expand All @@ -603,16 +595,16 @@ export class Remix extends Component implements Link.Linkable {
behaviors: [
edge
? {
cacheType: "server",
cfFunction: "serverCfFunction",
edgeFunction: "server",
origin: "s3",
}
cacheType: "server",
cfFunction: "serverCfFunction",
edgeFunction: "server",
origin: "s3",
}
: {
cacheType: "server",
cfFunction: "serverCfFunction",
origin: "server",
},
cacheType: "server",
cfFunction: "serverCfFunction",
origin: "server",
},
...buildMeta.staticRoutes.map(
(route) =>
({
Expand Down
8 changes: 0 additions & 8 deletions platform/src/components/aws/solid-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ export interface SolidStartArgs extends SsrSiteArgs {
* To disable dev mode, pass in `false`.
*/
dev?: false | DevArgs["dev"];
/**
* The number of instances of the [server function](#nodes-server) to keep warm. This is useful for cases where you are experiencing long cold starts. The default is to not keep any instances warm.
*
* This works by starting a serverless cron job to make _n_ concurrent requests to the server function every few minutes. Where _n_ is the number of instances to keep warm.
*
* @default `0`
*/
warm?: SsrSiteArgs["warm"];
/**
* Permissions and the resources that the [server function](#nodes-server) in your SolidStart app needs to access. These permissions are used to create the function's IAM role.
*
Expand Down
Loading

0 comments on commit 1e269ad

Please sign in to comment.