-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathnextjs-regional-functions.ts
More file actions
110 lines (100 loc) · 3.89 KB
/
Copy pathnextjs-regional-functions.ts
File metadata and controls
110 lines (100 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { Stack } from "aws-cdk-lib";
import { Construct } from "constructs";
import { NextjsType } from "../constants";
import { NextjsApi, NextjsApiOverrides, NextjsApiProps } from "../nextjs-api";
import {
NextjsBaseConstruct,
NextjsBaseProps,
NextjsBaseConstructOverrides,
NextjsBaseOverrides,
} from "./nextjs-base-construct";
import { OptionalNextjsPostDeployProps } from "../generated-structs/OptionalNextjsPostDeployProps";
import {
NextjsFunctions,
NextjsFunctionsOverrides,
NextjsFunctionsProps,
} from "../nextjs-compute/nextjs-functions";
import {
NextjsPostDeploy,
NextjsPostDeployOverrides,
} from "../nextjs-post-deploy";
export interface NextjsRegionalFunctionsConstructOverrides extends NextjsBaseConstructOverrides {
readonly nextjsFunctionsProps?: NextjsFunctionsProps;
readonly nextjsApiProps?: NextjsApiProps;
readonly nextjsPostDeployProps?: OptionalNextjsPostDeployProps;
}
/**
* Overrides for `NextjsRegionalFunctions`. Overrides are lower level than
* props and are passed directly to CDK Constructs giving you more control. It's
* recommended to use caution and review source code so you know how they're used.
*/
export interface NextjsRegionalFunctionsOverrides extends NextjsBaseOverrides {
readonly nextjsRegionalFunctions?: NextjsRegionalFunctionsConstructOverrides;
readonly nextjsFunctions?: NextjsFunctionsOverrides;
readonly nextjsApi?: NextjsApiOverrides;
readonly nextjsPostDeploy?: NextjsPostDeployOverrides;
}
export interface NextjsRegionalFunctionsProps extends NextjsBaseProps {
/**
* Override props of any construct.
*/
readonly overrides?: NextjsRegionalFunctionsOverrides;
}
/**
* Deploy Next.js regionally with functions. Uses API Gateway REST API
* for routing requests and AWS Lambda Functions for server-side rendering.
*/
export class NextjsRegionalFunctions extends NextjsBaseConstruct {
nextjsFunctions: NextjsFunctions;
nextjsApi: NextjsApi;
nextjsPostDeploy: NextjsPostDeploy;
get url(): string {
return `https://${this.nextjsApi.api.restApiId}.execute-api.${Stack.of(this).region}.amazonaws.com/${this.nextjsApi.api.deploymentStage.stageName}`;
}
private props: NextjsRegionalFunctionsProps;
constructor(
scope: Construct,
id: string,
props: NextjsRegionalFunctionsProps,
) {
super(scope, id, props, NextjsType.REGIONAL_FUNCTIONS);
this.props = props;
this.nextjsFunctions = this.createNextjsFunctions();
this.nextjsApi = this.createNextjsApi();
this.nextjsPostDeploy = this.createNextjsPostDeploy();
}
private createNextjsFunctions(): NextjsFunctions {
// Create functions with local build output
return new NextjsFunctions(this, "NextjsFunctions", {
...this.computeBaseProps(),
overrides: {
...this.props.overrides?.nextjsFunctions,
dockerImageFunctionProps: {
...this.props.overrides?.nextjsFunctions?.dockerImageFunctionProps,
vpc: this.baseProps.vpc,
},
},
...this.props.overrides?.nextjsRegionalFunctions?.nextjsFunctionsProps,
});
}
private createNextjsApi() {
return new NextjsApi(this, "NextjsApi", {
staticAssetsBucket: this.nextjsStaticAssets.bucket,
serverFunction: this.nextjsFunctions.function,
basePath: this.baseProps.basePath,
overrides: this.props.overrides?.nextjsApi,
publicDirEntries: this.nextjsBuild.publicDirEntries,
...this.props.overrides?.nextjsRegionalFunctions?.nextjsApiProps,
});
}
private createNextjsPostDeploy(): NextjsPostDeploy {
return new NextjsPostDeploy(this, "NextjsPostDeploy", {
buildId: this.nextjsBuild.buildId,
cacheBucket: this.nextjsCache.cacheBucket,
revalidationTable: this.nextjsCache.revalidationTable,
staticAssetsBucket: this.nextjsStaticAssets.bucket,
overrides: this.props.overrides?.nextjsPostDeploy,
...this.props.overrides?.nextjsRegionalFunctions?.nextjsPostDeployProps,
});
}
}