cdk-nuxt 0.5.0 → 0.6.1
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/README.md +73 -21
- package/index.d.ts +2 -3
- package/index.js +6 -6
- package/lib/cli/{deploy.js → deploy-server.js} +1 -1
- package/lib/cli/deploy-static.js +19 -0
- package/lib/cli/init-server.js +17 -0
- package/lib/cli/{init.js → init-static.js} +2 -2
- package/lib/functions/app/index.js +1 -1
- package/lib/stack/nuxt-app-stack-props.d.ts +43 -0
- package/lib/stack/nuxt-app-stack-props.js +3 -0
- package/lib/stack/nuxt-app-stack-props.ts +51 -0
- package/lib/stack/nuxt-app-static-assets.d.ts +4 -1
- package/lib/stack/nuxt-app-static-assets.js +110 -71
- package/lib/stack/nuxt-app-static-assets.ts +122 -73
- package/lib/stack/nuxt-config.d.ts +1 -0
- package/lib/stack/nuxt-config.js +1 -1
- package/lib/stack/nuxt-config.ts +1 -0
- package/lib/stack/{nuxt-app-stack.d.ts → server/nuxt-server-app-stack.d.ts} +31 -33
- package/lib/stack/server/nuxt-server-app-stack.js +389 -0
- package/lib/stack/{nuxt-app-stack.ts → server/nuxt-server-app-stack.ts} +114 -48
- package/lib/stack/static/nuxt-static-app-stack.d.ts +90 -0
- package/lib/stack/static/nuxt-static-app-stack.js +164 -0
- package/lib/stack/static/nuxt-static-app-stack.ts +226 -0
- package/lib/templates/{stack-index.ts → stack-index-server.ts} +19 -19
- package/lib/templates/stack-index-static.ts +45 -0
- package/package.json +9 -3
- package/lib/stack/app-stack-props.d.ts +0 -22
- package/lib/stack/app-stack-props.js +0 -3
- package/lib/stack/app-stack-props.ts +0 -26
- package/lib/stack/nuxt-app-assets-cleanup-stack.d.ts +0 -53
- package/lib/stack/nuxt-app-assets-cleanup-stack.js +0 -83
- package/lib/stack/nuxt-app-assets-cleanup-stack.ts +0 -114
- package/lib/stack/nuxt-app-stack.js +0 -314
package/README.md
CHANGED
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
<a href="https://www.npmjs.com/package/cdk-nuxt"><img alt="License" src="https://img.shields.io/npm/l/cdk-nuxt.svg" /></a>
|
|
7
7
|
</p>
|
|
8
8
|
|
|
9
|
-
Easily deploy
|
|
9
|
+
Easily deploy Nuxt applications via CDK on AWS including the following features:
|
|
10
10
|
|
|
11
|
-
- Fast responses via [Lambda](https://aws.amazon.com/lambda/)
|
|
12
|
-
- Publicly available by a custom domain (or subdomain) via [Route53](https://aws.amazon.com/route53/) and [API Gateway](https://aws.amazon.com/api-gateway/)
|
|
11
|
+
- Fast responses via [Lambda](https://aws.amazon.com/lambda/) (`target=server`) or [S3](https://aws.amazon.com/s3/) (`target=static`)
|
|
12
|
+
- Publicly available by a custom domain (or subdomain) via [Route53](https://aws.amazon.com/route53/) and [API Gateway](https://aws.amazon.com/api-gateway/) (`target=server`)
|
|
13
13
|
- Automatic redirects from HTTP to HTTPS via [CloudFront](https://aws.amazon.com/cloudfront/)
|
|
14
|
-
- Automatic upload of the
|
|
15
|
-
- Scheduled pings of the Nuxt app to keep the Lambda warm for fast responses via [EventBridge](https://aws.amazon.com/eventbridge/) rules
|
|
16
|
-
- Automatic cleanup of outdated static assets and build files
|
|
14
|
+
- Automatic upload of the build files for CSR and static assets to [S3](https://aws.amazon.com/s3/) with optimized caching rules
|
|
15
|
+
- Scheduled pings of the Nuxt app to keep the Lambda warm for fast responses via [EventBridge](https://aws.amazon.com/eventbridge/) rules (`target=server`)
|
|
16
|
+
- Automatic cleanup of outdated static assets and build files (`target=server`)
|
|
17
17
|
|
|
18
18
|
> :warning: **This package might not support every Nuxt config yet.** But feel free to give it a try and open an issue or a PR if necessary.
|
|
19
19
|
|
|
@@ -24,6 +24,11 @@ Easily deploy a dynamic universal Nuxt application via CDK on AWS including the
|
|
|
24
24
|
|
|
25
25
|
## Installation
|
|
26
26
|
|
|
27
|
+
Two CDK stacks can be used to deploy a Nuxt app to AWS using this package depending on the [app's target setting](https://nuxtjs.org/docs/configuration-glossary/configuration-target#the-target-property).
|
|
28
|
+
Therefore, follow the installation steps for your corresponding target setting.
|
|
29
|
+
|
|
30
|
+
### Target: 'server'
|
|
31
|
+
|
|
27
32
|
1. Install the package and its required dependencies:
|
|
28
33
|
```bash
|
|
29
34
|
yarn add cdk-nuxt --dev # The package itself
|
|
@@ -55,8 +60,20 @@ After the installation steps the `package.json` file should look something like
|
|
|
55
60
|
}
|
|
56
61
|
```
|
|
57
62
|
|
|
63
|
+
### Target: 'static'
|
|
64
|
+
|
|
65
|
+
Install the package and its required dependencies:
|
|
66
|
+
```bash
|
|
67
|
+
yarn add cdk-nuxt --dev # The package itself
|
|
68
|
+
yarn add ts-node typescript --dev # To compile the CDK stacks via typescript
|
|
69
|
+
yarn add aws-cdk@2.15.0 --dev # CDK cli with this exact version for the deployment
|
|
70
|
+
```
|
|
71
|
+
|
|
58
72
|
## Setup
|
|
59
73
|
|
|
74
|
+
Again, follow the steps according to the [app's target setting](https://nuxtjs.org/docs/configuration-glossary/configuration-target#the-target-property).
|
|
75
|
+
|
|
76
|
+
### Target: 'server'
|
|
60
77
|
1. Replace the `export default` part of your Nuxt configuration file (`nuxt.config.js`) with `module.exports =`, so it fits the following format:
|
|
61
78
|
```js
|
|
62
79
|
// Change "export default" => "module.exports ="
|
|
@@ -72,7 +89,19 @@ After the installation steps the `package.json` file should look something like
|
|
|
72
89
|
6. Run the following command to automatically create the required CDK stack entrypoint at `stack/index.ts`. This file defines the config how the Nuxt app will be deployed via CDK. You should adapt the file to the project's needs, especially the props `env.account` (setup step 2), `hostedZoneId` (setup step 3), `regionalTlsCertificateArn` (setup step 4) and `globalTlsCertificateArn` (setup step 5).
|
|
73
90
|
|
|
74
91
|
```bash
|
|
75
|
-
node_modules/.bin/cdk-nuxt-init
|
|
92
|
+
node_modules/.bin/cdk-nuxt-init-server
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
> :warning: It's recommended using a `.env` file or another secrets file to import the sensitive secrets into the `stack/index.ts` file.
|
|
96
|
+
|
|
97
|
+
### Target: 'static'
|
|
98
|
+
1. [Create an AWS account](https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/?nc1=h_ls), if you don't have one yet. Then login into the AWS console and note the `Account ID`. You will need it in step 4.
|
|
99
|
+
2. [Create a hosted zone in Route53](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/AboutHZWorkingWith.html) for the desired domain, if you don't have one yet.<br/>This is required to create DNS records for the domain to make the Nuxt app publicly available on that domain.<br/>On the hosted zone details you should see the `Hosted zone ID` of the hosted zone. You will need it in step 4.
|
|
100
|
+
3. [Request a public **global** certificate in the AWS Certificate Manager (ACM)](https://docs.aws.amazon.com/acm/latest/userguide/gs-acm-request-public.html) for the desired domain in `us-east-1` (**global**) and validate it, if you don't have one yet.<br/>This is required to provide the Nuxt app via HTTPS on the public internet.<br/>Take note of the displayed `ARN` for the certificate. You will need it in step 4.<br/>**Important: The certificate must be issued in us-east-1 (global) regardless of the region used for the Nuxt app itself as it will be attached to the Cloudfront distribution which works globally.**
|
|
101
|
+
4. Run the following command to automatically create the required CDK stack entrypoint at `stack/index.ts`. This file defines the config how the Nuxt app will be deployed via CDK. You should adapt the file to the project's needs, especially the props `env.account` (setup step 1), `hostedZoneId` (setup step 2), and `globalTlsCertificateArn` (setup step 3).
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
node_modules/.bin/cdk-nuxt-init-static
|
|
76
105
|
```
|
|
77
106
|
|
|
78
107
|
> :warning: It's recommended using a `.env` file or another secrets file to import the sensitive secrets into the `stack/index.ts` file.
|
|
@@ -80,7 +109,9 @@ After the installation steps the `package.json` file should look something like
|
|
|
80
109
|
## Build and Deploy
|
|
81
110
|
|
|
82
111
|
After the installation and the setup you are already good to go to build the Nuxt app and to deploy it to AWS with this package.
|
|
112
|
+
Again, follow the steps according to the [app's target setting](https://nuxtjs.org/docs/configuration-glossary/configuration-target#the-target-property).
|
|
83
113
|
|
|
114
|
+
### Target: 'server'
|
|
84
115
|
1. Install the dependencies for the Nuxt app including the `devDependencies` as these are required to successfully build the app:
|
|
85
116
|
```bash
|
|
86
117
|
yarn install --production=false
|
|
@@ -91,11 +122,11 @@ After the installation and the setup you are already good to go to build the Nux
|
|
|
91
122
|
```
|
|
92
123
|
3. Run the CDK deployment:
|
|
93
124
|
```bash
|
|
94
|
-
node_modules/.bin/cdk-nuxt-deploy
|
|
125
|
+
node_modules/.bin/cdk-nuxt-deploy-server
|
|
95
126
|
```
|
|
96
127
|
The deployment script will take care of installing only the dependencies that are required for the Nuxt app and deploying the Nuxt build files to AWS according to the stack settings in `stack/index.ts`.<br/>See the section Used AWS Resources for details on which resources will exactly be created on AWS.
|
|
97
128
|
|
|
98
|
-
|
|
129
|
+
#### Optional: Customize the Lambda handler
|
|
99
130
|
|
|
100
131
|
The package takes advantage of the `nuxt-start` and `aws-lambda` modules to automatically provide a Lambda handler for the Nuxt app.
|
|
101
132
|
If you need more control over the entrypoint of the Lambda function, e.g., for adding additional logging or performance monitoring, feel free to specify your own handler within a file `server/index.js` within your root directory.
|
|
@@ -118,7 +149,7 @@ const app = nuxt.server.app;
|
|
|
118
149
|
let serverlessExpressInstance = null;
|
|
119
150
|
async function initNuxt(event, context) {
|
|
120
151
|
await nuxt.ready();
|
|
121
|
-
serverlessExpressInstance = serverlessExpress({ app
|
|
152
|
+
serverlessExpressInstance = serverlessExpress({ app })
|
|
122
153
|
|
|
123
154
|
return serverlessExpressInstance(event, context)
|
|
124
155
|
}
|
|
@@ -132,6 +163,22 @@ exports.handler = async (event, context) => {
|
|
|
132
163
|
}
|
|
133
164
|
```
|
|
134
165
|
|
|
166
|
+
### Target: 'static'
|
|
167
|
+
1. Install the dependencies for the Nuxt app including the `devDependencies` as these are required to successfully build the app:
|
|
168
|
+
```bash
|
|
169
|
+
yarn install --production=false
|
|
170
|
+
```
|
|
171
|
+
2. Build the Nuxt app with the build settings you need for the app:
|
|
172
|
+
```bash
|
|
173
|
+
yarn generate
|
|
174
|
+
```
|
|
175
|
+
3. Run the CDK deployment:
|
|
176
|
+
```bash
|
|
177
|
+
node_modules/.bin/cdk-nuxt-deploy-static
|
|
178
|
+
```
|
|
179
|
+
The deployment script will take care of deploying the Nuxt build files to AWS according to the stack settings in `stack/index.ts`.<br/>See the section Used AWS Resources for details on which resources will exactly be created on AWS.
|
|
180
|
+
|
|
181
|
+
|
|
135
182
|
## Optional: Automatically deploy on every push (CD) via [GitHub Actions](https://github.com/features/actions)
|
|
136
183
|
|
|
137
184
|
Feel free to copy the following GitHub Actions YAML file content into a YAML file at `.github/workflows/deploy.yml` to automatically build and deploy the Nuxt app to AWS on every push to a specific branch.<br/>This only works if you're using GitHub for the project's VCS repository.
|
|
@@ -177,10 +224,10 @@ jobs:
|
|
|
177
224
|
run: yarn install --production=false # Important to install devDependencies for the build
|
|
178
225
|
|
|
179
226
|
- name: Build project
|
|
180
|
-
run: yarn build #
|
|
227
|
+
run: yarn build # (or yarn generate)
|
|
181
228
|
|
|
182
229
|
- name: Deploy to AWS
|
|
183
|
-
run: node_modules/.bin/nuxt-deploy
|
|
230
|
+
run: node_modules/.bin/cdk-nuxt-deploy-server # (or node_modules/.bin/cdk-nuxt-deploy-static)
|
|
184
231
|
env:
|
|
185
232
|
# Create an IAM user on AWS for the deployment and create the appropriate secrets in the GitHub repository secrets
|
|
186
233
|
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
@@ -190,24 +237,29 @@ jobs:
|
|
|
190
237
|
|
|
191
238
|
## Advanced: Used AWS Resources
|
|
192
239
|
|
|
193
|
-
Two CDK stacks
|
|
240
|
+
Two CDK stacks can be used to deploy a Nuxt app to AWS using this package depending on the [app's target setting](https://nuxtjs.org/docs/configuration-glossary/configuration-target#the-target-property).
|
|
194
241
|
|
|
195
|
-
###
|
|
242
|
+
### NuxtServerAppStack ([`target=server`](https://nuxtjs.org/docs/features/deployment-targets))
|
|
196
243
|
|
|
197
|
-
This
|
|
244
|
+
This stack is responsible for deploying dynamic Nuxt apps (`target=server`) to AWS.
|
|
198
245
|
The following AWS resources will be created by this stack:
|
|
199
246
|
|
|
200
|
-
- [Lambda](https://aws.amazon.com/lambda/):
|
|
247
|
+
- [Lambda](https://aws.amazon.com/lambda/):
|
|
248
|
+
- A Lambda function to render the Nuxt app including a separated Lambda layer to provide the `node_modules` of the Nuxt app required for server-side rendering.
|
|
249
|
+
- A Lambda function that deletes the outdated static assets of the Nuxt app from S3.
|
|
201
250
|
- [S3](https://aws.amazon.com/s3/): A bucket to store the client files of the Nuxt build (`.nuxt/dist/client`) and the custom static files of the Nuxt app (`static`) with optimized cache settings.
|
|
202
251
|
- [Route53](https://aws.amazon.com/route53/): Two DNS records (`A` for IPv4 and `AAAA` for IPv6) in the configured hosted zone to make the Nuxt app available on the internet via the configured custom domain.
|
|
203
252
|
- [API Gateway](https://aws.amazon.com/api-gateway/): An HTTP API to make the Nuxt Lambda function publicly available.
|
|
204
253
|
- [CloudFront](https://aws.amazon.com/cloudfront/): A distribution to route incoming requests to the Nuxt Lambda function (via the API Gateway) and the S3 bucket to serve the static assets for the Nuxt app.
|
|
205
|
-
- [EventBridge](https://aws.amazon.com/eventbridge/):
|
|
254
|
+
- [EventBridge](https://aws.amazon.com/eventbridge/):
|
|
255
|
+
- A scheduled rule to ping the Nuxt app's Lambda function every 5 minutes in order to keep it warm and to speed up initial SSR requests.
|
|
256
|
+
- A scheduled rule to trigger the cleanup Lambda function for deleting the outdated static assets of the Nuxt app from S3 every tuesday at 03:30 AM GMT.
|
|
206
257
|
|
|
207
|
-
###
|
|
258
|
+
### NuxtStaticAppStack ([`target=static`](https://nuxtjs.org/docs/features/deployment-targets))
|
|
208
259
|
|
|
209
|
-
This stack is responsible for
|
|
260
|
+
This stack is responsible for deploying static Nuxt apps (`target=static`) to AWS.
|
|
210
261
|
The following AWS resources will be created by this stack:
|
|
211
262
|
|
|
212
|
-
- [
|
|
213
|
-
- [
|
|
263
|
+
- [S3](https://aws.amazon.com/s3/): A bucket configured as website host to provide the files of the Nuxt build (`dist`) including the custom static files of the Nuxt app (`static`) with optimized cache settings.
|
|
264
|
+
- [Route53](https://aws.amazon.com/route53/): Two DNS records (`A` for IPv4 and `AAAA` for IPv6) in the configured hosted zone to make the Nuxt app available on the internet via the configured custom domain.
|
|
265
|
+
- [CloudFront](https://aws.amazon.com/cloudfront/): A distribution to route incoming requests to the S3 bucket to serve the Nuxt app.
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export { NuxtAppAssetsCleanupStack, NuxtAppAssetsCleanupProps } from "./lib/stack/nuxt-app-assets-cleanup-stack";
|
|
1
|
+
export { NuxtServerAppStack, NuxtServerAppStackProps } from "./lib/stack/server/nuxt-server-app-stack";
|
|
2
|
+
export { NuxtStaticAppStack, NuxtStaticAppStackProps } from "./lib/stack/static/nuxt-static-app-stack";
|
package/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "
|
|
8
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
3
|
+
exports.NuxtStaticAppStack = exports.NuxtServerAppStack = void 0;
|
|
4
|
+
var nuxt_server_app_stack_1 = require("./lib/stack/server/nuxt-server-app-stack");
|
|
5
|
+
Object.defineProperty(exports, "NuxtServerAppStack", { enumerable: true, get: function () { return nuxt_server_app_stack_1.NuxtServerAppStack; } });
|
|
6
|
+
var nuxt_static_app_stack_1 = require("./lib/stack/static/nuxt-static-app-stack");
|
|
7
|
+
Object.defineProperty(exports, "NuxtStaticAppStack", { enumerable: true, get: function () { return nuxt_static_app_stack_1.NuxtStaticAppStack; } });
|
|
8
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSxrRkFBb0c7QUFBNUYsMkhBQUEsa0JBQWtCLE9BQUE7QUFDMUIsa0ZBQW9HO0FBQTVGLDJIQUFBLGtCQUFrQixPQUFBIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IHtOdXh0U2VydmVyQXBwU3RhY2ssIE51eHRTZXJ2ZXJBcHBTdGFja1Byb3BzfSBmcm9tIFwiLi9saWIvc3RhY2svc2VydmVyL251eHQtc2VydmVyLWFwcC1zdGFja1wiXG5leHBvcnQge051eHRTdGF0aWNBcHBTdGFjaywgTnV4dFN0YXRpY0FwcFN0YWNrUHJvcHN9IGZyb20gXCIuL2xpYi9zdGFjay9zdGF0aWMvbnV4dC1zdGF0aWMtYXBwLXN0YWNrXCJcbiJdfQ==
|
|
@@ -4,7 +4,7 @@ const shell = require("shelljs");
|
|
|
4
4
|
const path = require("path");
|
|
5
5
|
|
|
6
6
|
const logPrefix = 'CDK Nuxt Deployment';
|
|
7
|
-
shell.echo(`${logPrefix}: Starting deployment...`);
|
|
7
|
+
shell.echo(`${logPrefix}: Starting deployment for dynamic Nuxt app...`);
|
|
8
8
|
|
|
9
9
|
const deploymentFolder = '.nuxt/cdk-deployment';
|
|
10
10
|
const deploymentSourceFolder = `${deploymentFolder}/src`;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const shell = require("shelljs");
|
|
4
|
+
|
|
5
|
+
const logPrefix = 'CDK Nuxt Deployment';
|
|
6
|
+
shell.echo(`${logPrefix}: Starting deployment for static Nuxt app...`);
|
|
7
|
+
|
|
8
|
+
// Refresh the cdk output folder to have a clean state and prevent persisting outdated outputs
|
|
9
|
+
shell.echo(`${logPrefix}: Deleting outdated CDK files...`);
|
|
10
|
+
shell.rm('-rf', 'cdk.out');
|
|
11
|
+
|
|
12
|
+
// Run the deployment
|
|
13
|
+
shell.echo(`${logPrefix}: Running deployment to AWS via CDK...`);
|
|
14
|
+
if (shell.exec('yarn cdk deploy --require-approval never --all --app="yarn ts-node stack/index.ts" ' + process.argv.slice(2)).code !== 0) {
|
|
15
|
+
shell.echo(`${logPrefix} Error: CDK deployment failed.`);
|
|
16
|
+
shell.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
shell.echo(`${logPrefix}: CDK deployment successful.`);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const shell = require("shelljs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
|
|
7
|
+
const logPrefix = 'CDK Nuxt Init';
|
|
8
|
+
|
|
9
|
+
shell.echo(`${logPrefix}: Initializing CDK stack index file for a dynamic Nuxt app...`);
|
|
10
|
+
|
|
11
|
+
if (!fs.existsSync('stack')) {
|
|
12
|
+
shell.mkdir('-p', 'stack');
|
|
13
|
+
shell.cp(path.join(__dirname, '../templates/stack-index-server.ts'), 'stack/index.ts');
|
|
14
|
+
shell.echo(`${logPrefix}: CDK stack index file created. Please adapt the file at 'stack/index.ts' to the project's needs.`);
|
|
15
|
+
} else {
|
|
16
|
+
shell.echo(`${logPrefix}: CDK stack folder already exists.`);
|
|
17
|
+
}
|
|
@@ -6,11 +6,11 @@ const fs = require("fs");
|
|
|
6
6
|
|
|
7
7
|
const logPrefix = 'CDK Nuxt Init';
|
|
8
8
|
|
|
9
|
-
shell.echo(`${logPrefix}: Initializing CDK stack index file...`);
|
|
9
|
+
shell.echo(`${logPrefix}: Initializing CDK stack index file for a static Nuxt app...`);
|
|
10
10
|
|
|
11
11
|
if (!fs.existsSync('stack')) {
|
|
12
12
|
shell.mkdir('-p', 'stack');
|
|
13
|
-
shell.cp(path.join(__dirname, '../templates/stack-index.ts'), 'stack/index.ts');
|
|
13
|
+
shell.cp(path.join(__dirname, '../templates/stack-index-static.ts'), 'stack/index.ts');
|
|
14
14
|
shell.echo(`${logPrefix}: CDK stack index file created. Please adapt the file at 'stack/index.ts' to the project's needs.`);
|
|
15
15
|
} else {
|
|
16
16
|
shell.echo(`${logPrefix}: CDK stack folder already exists.`);
|
|
@@ -12,7 +12,7 @@ const app = nuxt.server.app;
|
|
|
12
12
|
let serverlessExpressInstance = null;
|
|
13
13
|
async function initNuxt(event, context) {
|
|
14
14
|
await nuxt.ready();
|
|
15
|
-
serverlessExpressInstance = serverlessExpress({ app
|
|
15
|
+
serverlessExpressInstance = serverlessExpress({ app })
|
|
16
16
|
|
|
17
17
|
return serverlessExpressInstance(event, context)
|
|
18
18
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { StackProps } from "aws-cdk-lib";
|
|
2
|
+
import { NuxtConfig } from "./nuxt-config";
|
|
3
|
+
/**
|
|
4
|
+
* Defines the common props required to deploy Nuxt apps on AWS.
|
|
5
|
+
*/
|
|
6
|
+
export interface NuxtAppStackProps extends StackProps {
|
|
7
|
+
/**
|
|
8
|
+
* A string identifier for the project the Nuxt app is part of.
|
|
9
|
+
* A project might have multiple different services.
|
|
10
|
+
*/
|
|
11
|
+
readonly project: string;
|
|
12
|
+
/**
|
|
13
|
+
* A string identifier for the project's service the Nuxt app is created for.
|
|
14
|
+
* This can be seen as the name of the Nuxt app.
|
|
15
|
+
*/
|
|
16
|
+
readonly service: string;
|
|
17
|
+
/**
|
|
18
|
+
* A string to identify the environment of the Nuxt app. This enables us
|
|
19
|
+
* to deploy multiple different environments of the same Nuxt app, e.g., production and development.
|
|
20
|
+
*/
|
|
21
|
+
readonly environment: string;
|
|
22
|
+
/**
|
|
23
|
+
* The domain (without the protocol) at which the Nuxt app shall be publicly available.
|
|
24
|
+
* A DNS record will be automatically created in Route53 for the domain.
|
|
25
|
+
* This also supports subdomains.
|
|
26
|
+
* Examples: "example.com", "sub.example.com"
|
|
27
|
+
*/
|
|
28
|
+
readonly domain: string;
|
|
29
|
+
/**
|
|
30
|
+
* The id of the hosted zone to create a DNS record for the specified domain.
|
|
31
|
+
*/
|
|
32
|
+
readonly hostedZoneId: string;
|
|
33
|
+
/**
|
|
34
|
+
* The ARN of the certificate to use on CloudFront for the Nuxt app to make it accessible via HTTPS.
|
|
35
|
+
* The certificate must be issued for the specified domain in us-east-1 (global) regardless of the
|
|
36
|
+
* region specified via 'env.region' as CloudFront only works globally.
|
|
37
|
+
*/
|
|
38
|
+
readonly globalTlsCertificateArn: string;
|
|
39
|
+
/**
|
|
40
|
+
* The nuxt.config.js of the Nuxt app.
|
|
41
|
+
*/
|
|
42
|
+
readonly nuxtConfig: NuxtConfig;
|
|
43
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnV4dC1hcHAtc3RhY2stcHJvcHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJudXh0LWFwcC1zdGFjay1wcm9wcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHtTdGFja1Byb3BzfSBmcm9tIFwiYXdzLWNkay1saWJcIjtcbmltcG9ydCB7TnV4dENvbmZpZ30gZnJvbSBcIi4vbnV4dC1jb25maWdcIjtcblxuLyoqXG4gKiBEZWZpbmVzIHRoZSBjb21tb24gcHJvcHMgcmVxdWlyZWQgdG8gZGVwbG95IE51eHQgYXBwcyBvbiBBV1MuXG4gKi9cbmV4cG9ydCBpbnRlcmZhY2UgTnV4dEFwcFN0YWNrUHJvcHMgZXh0ZW5kcyBTdGFja1Byb3BzIHtcblxuICAgIC8qKlxuICAgICAqIEEgc3RyaW5nIGlkZW50aWZpZXIgZm9yIHRoZSBwcm9qZWN0IHRoZSBOdXh0IGFwcCBpcyBwYXJ0IG9mLlxuICAgICAqIEEgcHJvamVjdCBtaWdodCBoYXZlIG11bHRpcGxlIGRpZmZlcmVudCBzZXJ2aWNlcy5cbiAgICAgKi9cbiAgICByZWFkb25seSBwcm9qZWN0OiBzdHJpbmc7XG5cbiAgICAvKipcbiAgICAgKiBBIHN0cmluZyBpZGVudGlmaWVyIGZvciB0aGUgcHJvamVjdCdzIHNlcnZpY2UgdGhlIE51eHQgYXBwIGlzIGNyZWF0ZWQgZm9yLlxuICAgICAqIFRoaXMgY2FuIGJlIHNlZW4gYXMgdGhlIG5hbWUgb2YgdGhlIE51eHQgYXBwLlxuICAgICAqL1xuICAgIHJlYWRvbmx5IHNlcnZpY2U6IHN0cmluZztcblxuICAgIC8qKlxuICAgICAqIEEgc3RyaW5nIHRvIGlkZW50aWZ5IHRoZSBlbnZpcm9ubWVudCBvZiB0aGUgTnV4dCBhcHAuIFRoaXMgZW5hYmxlcyB1c1xuICAgICAqIHRvIGRlcGxveSBtdWx0aXBsZSBkaWZmZXJlbnQgZW52aXJvbm1lbnRzIG9mIHRoZSBzYW1lIE51eHQgYXBwLCBlLmcuLCBwcm9kdWN0aW9uIGFuZCBkZXZlbG9wbWVudC5cbiAgICAgKi9cbiAgICByZWFkb25seSBlbnZpcm9ubWVudDogc3RyaW5nO1xuXG4gICAgLyoqXG4gICAgICogVGhlIGRvbWFpbiAod2l0aG91dCB0aGUgcHJvdG9jb2wpIGF0IHdoaWNoIHRoZSBOdXh0IGFwcCBzaGFsbCBiZSBwdWJsaWNseSBhdmFpbGFibGUuXG4gICAgICogQSBETlMgcmVjb3JkIHdpbGwgYmUgYXV0b21hdGljYWxseSBjcmVhdGVkIGluIFJvdXRlNTMgZm9yIHRoZSBkb21haW4uXG4gICAgICogVGhpcyBhbHNvIHN1cHBvcnRzIHN1YmRvbWFpbnMuXG4gICAgICogRXhhbXBsZXM6IFwiZXhhbXBsZS5jb21cIiwgXCJzdWIuZXhhbXBsZS5jb21cIlxuICAgICAqL1xuICAgIHJlYWRvbmx5IGRvbWFpbjogc3RyaW5nO1xuXG4gICAgLyoqXG4gICAgICogVGhlIGlkIG9mIHRoZSBob3N0ZWQgem9uZSB0byBjcmVhdGUgYSBETlMgcmVjb3JkIGZvciB0aGUgc3BlY2lmaWVkIGRvbWFpbi5cbiAgICAgKi9cbiAgICByZWFkb25seSBob3N0ZWRab25lSWQ6IHN0cmluZztcblxuICAgIC8qKlxuICAgICAqIFRoZSBBUk4gb2YgdGhlIGNlcnRpZmljYXRlIHRvIHVzZSBvbiBDbG91ZEZyb250IGZvciB0aGUgTnV4dCBhcHAgdG8gbWFrZSBpdCBhY2Nlc3NpYmxlIHZpYSBIVFRQUy5cbiAgICAgKiBUaGUgY2VydGlmaWNhdGUgbXVzdCBiZSBpc3N1ZWQgZm9yIHRoZSBzcGVjaWZpZWQgZG9tYWluIGluIHVzLWVhc3QtMSAoZ2xvYmFsKSByZWdhcmRsZXNzIG9mIHRoZVxuICAgICAqIHJlZ2lvbiBzcGVjaWZpZWQgdmlhICdlbnYucmVnaW9uJyBhcyBDbG91ZEZyb250IG9ubHkgd29ya3MgZ2xvYmFsbHkuXG4gICAgICovXG4gICAgcmVhZG9ubHkgZ2xvYmFsVGxzQ2VydGlmaWNhdGVBcm46IHN0cmluZztcblxuICAgIC8qKlxuICAgICAqIFRoZSBudXh0LmNvbmZpZy5qcyBvZiB0aGUgTnV4dCBhcHAuXG4gICAgICovXG4gICAgcmVhZG9ubHkgbnV4dENvbmZpZzogTnV4dENvbmZpZztcbn0iXX0=
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {StackProps} from "aws-cdk-lib";
|
|
2
|
+
import {NuxtConfig} from "./nuxt-config";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Defines the common props required to deploy Nuxt apps on AWS.
|
|
6
|
+
*/
|
|
7
|
+
export interface NuxtAppStackProps extends StackProps {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A string identifier for the project the Nuxt app is part of.
|
|
11
|
+
* A project might have multiple different services.
|
|
12
|
+
*/
|
|
13
|
+
readonly project: string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A string identifier for the project's service the Nuxt app is created for.
|
|
17
|
+
* This can be seen as the name of the Nuxt app.
|
|
18
|
+
*/
|
|
19
|
+
readonly service: string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A string to identify the environment of the Nuxt app. This enables us
|
|
23
|
+
* to deploy multiple different environments of the same Nuxt app, e.g., production and development.
|
|
24
|
+
*/
|
|
25
|
+
readonly environment: string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The domain (without the protocol) at which the Nuxt app shall be publicly available.
|
|
29
|
+
* A DNS record will be automatically created in Route53 for the domain.
|
|
30
|
+
* This also supports subdomains.
|
|
31
|
+
* Examples: "example.com", "sub.example.com"
|
|
32
|
+
*/
|
|
33
|
+
readonly domain: string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The id of the hosted zone to create a DNS record for the specified domain.
|
|
37
|
+
*/
|
|
38
|
+
readonly hostedZoneId: string;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The ARN of the certificate to use on CloudFront for the Nuxt app to make it accessible via HTTPS.
|
|
42
|
+
* The certificate must be issued for the specified domain in us-east-1 (global) regardless of the
|
|
43
|
+
* region specified via 'env.region' as CloudFront only works globally.
|
|
44
|
+
*/
|
|
45
|
+
readonly globalTlsCertificateArn: string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The nuxt.config.js of the Nuxt app.
|
|
49
|
+
*/
|
|
50
|
+
readonly nuxtConfig: NuxtConfig;
|
|
51
|
+
}
|
|
@@ -22,9 +22,12 @@ export interface StaticAssetConfig {
|
|
|
22
22
|
* The cache settings to use for the uploaded source files when accessing them on the target path with the specified pattern.
|
|
23
23
|
*/
|
|
24
24
|
cacheControl?: CacheControl[];
|
|
25
|
+
/**
|
|
26
|
+
* Whether to invalidate the files matching the config's pattern in the distribution's edge caches after the files are uploaded to the destination bucket.
|
|
27
|
+
*/
|
|
28
|
+
invalidateOnChange?: boolean;
|
|
25
29
|
}
|
|
26
30
|
/**
|
|
27
31
|
* Retrieves the static assets of the Nuxt app that shall be publicly available.
|
|
28
|
-
* These should match the files in '.nuxt/dist/client' and 'static'.
|
|
29
32
|
*/
|
|
30
33
|
export declare const getNuxtAppStaticAssetConfigs: (nuxtConfig: NuxtConfig) => StaticAssetConfig[];
|