Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/build/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,16 @@ export const getNextCachedRoutesConfig = async (
const prerenderManifest = JSON.parse(prerenderManifestJSON) as PrerenderManifest
const routesManifest = JSON.parse(routesManifestJSON) as RoutesManifest

const locales = routesManifest.i18n?.locales ?? []

const cachedRoutesMatchers = [...routesManifest.dynamicRoutes, ...routesManifest.staticRoutes].reduce(
(prev, route) => {
if (prerenderManifest.routes?.[route.page] || prerenderManifest.dynamicRoutes?.[route.page]) {
prev.push(route.regex)
if (locales.length) {
prev.push(...locales.map((locale) => route.regex.replace('^', `^/${locale}`)))
} else {
prev.push(route.regex)
}
}

return prev
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/constructs/CloudFrontDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const OneMonthCache = Duration.days(30)
const NoCache = Duration.seconds(0)

const defaultNextQueries = ['_rsc']
const defaultNextHeaders = ['Cache-Control', 'Next-Router-State-Tree', 'Next-Url', 'Rsc', 'Next-Router-Prefetch']
const defaultNextHeaders = ['Next-Router-State-Tree', 'Next-Url', 'Rsc', 'Next-Router-Prefetch']
const imageQueries = ['w', 'h', 'url', 'q']
export class CloudFrontDistribution extends Construct {
public readonly cf: cloudfront.Distribution
Expand Down
25 changes: 22 additions & 3 deletions src/cdk/constructs/RenderServerDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface RenderServerDistributionProps {
minInstances?: number
maxInstances?: number
dynamoDBCacheTable: string
healthCheckPath?: string
}

const NodeJSEnvironmentMapping: Record<string, string> = {
Expand Down Expand Up @@ -46,7 +47,8 @@ export class RenderServerDistribution extends Construct {
instanceType = 't2.micro',
minInstances = 1,
maxInstances = 2,
dynamoDBCacheTable
dynamoDBCacheTable,
healthCheckPath = '/'
} = props

this.vpc = new Vpc(this, 'BeanstalkVPC', {
Expand Down Expand Up @@ -82,6 +84,13 @@ export class RenderServerDistribution extends Construct {
managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName('AWSElasticBeanstalkWebTier')]
})

this.ebInstanceProfileRole.addToPolicy(
new iam.PolicyStatement({
actions: ['logs:PutLogEvents', 'logs:CreateLogStream', 'logs:DescribeLogGroups', 'logs:DescribeLogStreams'],
resources: ['*']
})
)

this.ebInstanceProfileRole.addToPolicy(
new iam.PolicyStatement({
actions: ['s3:Get*', 's3:Put*', 's3:Delete*', 's3:ListBucket'],
Expand Down Expand Up @@ -131,6 +140,11 @@ export class RenderServerDistribution extends Construct {
optionName: 'LoadBalancerType',
value: 'application'
},
{
namespace: 'aws:elasticbeanstalk:environment:process:default',
optionName: 'HealthCheckPath',
value: healthCheckPath
},
{
namespace: 'aws:autoscaling:launchconfiguration',
optionName: 'InstanceType',
Expand Down Expand Up @@ -174,12 +188,12 @@ export class RenderServerDistribution extends Construct {
{
namespace: 'aws:autoscaling:trigger',
optionName: 'UpperThreshold',
value: '75'
value: '60'
},
{
namespace: 'aws:autoscaling:trigger',
optionName: 'LowerThreshold',
value: '40'
value: '30'
},
{
namespace: 'aws:ec2:vpc',
Expand All @@ -195,6 +209,11 @@ export class RenderServerDistribution extends Construct {
namespace: 'aws:ec2:vpc',
optionName: 'ELBSubnets',
value: publicSubnets.join(',')
},
{
namespace: 'aws:elasticbeanstalk:cloudwatch:logs',
optionName: 'StreamLogs',
value: 'true'
}
]
})
Expand Down
7 changes: 5 additions & 2 deletions src/cdk/stacks/NextRenderServerStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface NextRenderServerStackProps extends cdk.StackProps {
renderServerInstanceType?: string
renderServerMinInstances?: number
renderServerMaxInstances?: number
healthCheckPath?: string
}

export class NextRenderServerStack extends cdk.Stack {
Expand All @@ -35,7 +36,8 @@ export class NextRenderServerStack extends cdk.Stack {
region,
renderServerInstanceType,
renderServerMinInstances,
renderServerMaxInstances
renderServerMaxInstances,
healthCheckPath
} = props

this.staticBucketName = `${id}-static`
Expand Down Expand Up @@ -68,7 +70,8 @@ export class NextRenderServerStack extends cdk.Stack {
instanceType: renderServerInstanceType,
minInstances: renderServerMinInstances,
maxInstances: renderServerMaxInstances,
dynamoDBCacheTable: this.dynamoDB.table.tableName
dynamoDBCacheTable: this.dynamoDB.table.tableName,
healthCheckPath
})

this.renderWorker = new RenderWorkerDistribution(this, `${id}-renderWorker`, {
Expand Down
1 change: 1 addition & 0 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const deploy = async (config: DeployConfig) => {
renderServerInstanceType,
renderServerMaxInstances,
renderServerMinInstances,
healthCheckPath: deployConfig.healthCheckPath,
env: {
region
}
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface CacheConfig {

export interface DeployConfig {
cache: CacheConfig
healthCheckPath?: string
publicAssets?: {
prefix: string
ttl?: number
Expand Down