cdk-nuxt 2.17.0 → 2.18.2

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ferdinand Frank
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md CHANGED
@@ -9,371 +9,196 @@
9
9
 
10
10
  Easily deploy Nuxt applications (Nuxt 3 and Nuxt 4) via CDK on AWS, including the following features:
11
11
 
12
- - Fast responses via [AWS Lambda](https://aws.amazon.com/lambda/)
13
- - Publicly available by a custom domain (or subdomain) via [Route53](https://aws.amazon.com/route53/) and [API Gateway](https://aws.amazon.com/api-gateway/)
14
- - Automatic redirects from HTTP to HTTPS via [CloudFront](https://aws.amazon.com/cloudfront/)
15
- - Automatic upload of the build files for CSR and static assets to [S3](https://aws.amazon.com/s3/) with optimized caching rules
16
- - Scheduled pings of the Nuxt app to keep the Lambda warm for fast responses via [EventBridge](https://aws.amazon.com/eventbridge/) rules
17
- - Automatic cleanup of outdated static assets and build files
18
- - Access logs analysis via [Athena](https://aws.amazon.com/athena/) for the Nuxt app's CloudFront distribution
12
+ - ⚡ **Fast responses** via [AWS Lambda](https://aws.amazon.com/lambda/)
13
+ - 🌐 **Custom domain** support via [Route53](https://aws.amazon.com/route53/) and [CloudFront](https://aws.amazon.com/cloudfront/)
14
+ - 🔒 **Automatic HTTPS** with certificate management
15
+ - 📦 **Optimized static asset** delivery via [S3](https://aws.amazon.com/s3/)
16
+ - 🔥 **Lambda warming** via scheduled [EventBridge](https://aws.amazon.com/eventbridge/) pings
17
+ - 🗑️ **Automatic cleanup** of outdated assets
18
+ - 📊 **Access logs analysis** via [Athena](https://aws.amazon.com/athena/) ([docs](docs/ACCESS_LOGS.md))
19
+ - 🛡️ **WAF integration** for security ([docs](docs/WAF.md))
20
+ - ⚙️ **Flexible caching** configuration ([docs](docs/CACHING.md))
21
+
22
+ ## Quick Links
23
+
24
+ - 📚 [Full Configuration Reference](docs/CONFIGURATION.md)
25
+ - 🚀 [Deployment Guide](docs/DEPLOYMENT.md)
26
+ - 🛡️ [WAF Documentation](docs/WAF.md)
27
+ - 📊 [Access Logs Analysis](docs/ACCESS_LOGS.md)
28
+ - 🔄 [Caching Configuration](docs/CACHING.md)
19
29
 
20
30
  ## Table of Contents
21
31
 
22
- - [Prerequisites](#prerequisites)
23
32
  - [Compatibility](#compatibility)
24
- - [Installation](#installation)
25
- - [Setup](#setup)
26
- - [Configuration](#configuration)
27
- - [Deployment](#deployment)
28
- - [Destroy the Stack](#destroy-the-stack)
29
- - [Reference: Created AWS Resources](#reference-created-aws-resources)
30
- - [Guidelines](#guidelines)
31
-
32
- ## Prerequisites
33
-
34
- - You need an [AWS account](https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/?nc1=h_ls) to create and deploy the required resources for the Nuxt app on AWS.
35
- - You can use your preferred package manager: pnpm, npm, or Yarn. The examples below show commands for each where relevant.
33
+ - [Quick Start](#quick-start)
34
+ - [AWS Resources Created](#aws-resources-created)
35
+ - [Documentation](#documentation)
36
36
 
37
37
  ## Compatibility
38
38
 
39
- This package is compatible with the following Nuxt versions:
40
- - Nuxt 3 (latest stable)
41
- - Nuxt 4 (RC and stable)
39
+ - Nuxt 3 (latest stable)
40
+ - Nuxt 4 (RC and stable)
42
41
 
43
- Notes:
44
- - Make sure to set Nitro's preset to `aws-lambda` as shown below.
45
- - If you encounter any version-specific issues, please open an issue on GitHub.
42
+ ## Quick Start
46
43
 
47
- ## Installation
44
+ ### 1. Installation
48
45
 
49
- This library ships compiled JS and small CLI helpers. To use it in your CDK app, install the following in your project by choosing your package manager:
46
+ Install the package and its peer dependencies:
50
47
 
51
- Using pnpm:
52
48
  ```bash
53
- pnpm add -D cdk-nuxt aws-cdk@^2.214.0 aws-cdk-lib@^2.214.0 constructs@^10.4.2
54
- # If your CDK app is written in TypeScript:
55
- pnpm add -D typescript ts-node
56
- # Optional (only if you enable Access Logs Analysis):
57
- pnpm add -D @aws-cdk/aws-glue-alpha@2.214.0-alpha.0
58
- ```
49
+ # Using pnpm (recommended)
50
+ pnpm add -D cdk-nuxt aws-cdk@^2.214.0 aws-cdk-lib@^2.214.0 constructs@^10.4.2 typescript ts-node
59
51
 
60
- Using npm:
61
- ```bash
62
- npm install --save-dev cdk-nuxt aws-cdk@^2.214.0 aws-cdk-lib@^2.214.0 constructs@^10.4.2
63
- # If your CDK app is written in TypeScript:
64
- npm install --save-dev typescript ts-node
65
- # Optional (only if you enable Access Logs Analysis):
66
- npm install --save-dev @aws-cdk/aws-glue-alpha@2.214.0-alpha.0
52
+ # Using npm
53
+ npm install --save-dev cdk-nuxt aws-cdk@^2.214.0 aws-cdk-lib@^2.214.0 constructs@^10.4.2 typescript ts-node
54
+
55
+ # Using yarn
56
+ yarn add -D cdk-nuxt aws-cdk@^2.214.0 aws-cdk-lib@^2.214.0 constructs@^10.4.2 typescript ts-node
67
57
  ```
68
58
 
69
- Using Yarn:
59
+ **Optional:** If you plan to enable Access Logs Analysis:
70
60
  ```bash
71
- yarn add -D cdk-nuxt aws-cdk@^2.214.0 aws-cdk-lib@^2.214.0 constructs@^10.4.2
72
- # If your CDK app is written in TypeScript:
73
- yarn add -D typescript ts-node
74
- # Optional (only if you enable Access Logs Analysis):
75
- yarn add -D @aws-cdk/aws-glue-alpha@2.214.0-alpha.0
61
+ pnpm add -D @aws-cdk/aws-glue-alpha@2.214.0-alpha.0
76
62
  ```
77
63
 
78
- ## Setup
79
-
80
- 1. Set the Nitro preset on your Nuxt configuration file (`nuxt.config.js`) to `aws-lambda`:
81
- ```js
82
- export default defineNuxtConfig({
83
- ...
84
- nitro: {
85
- preset: 'aws-lambda'
86
- },
87
- ...
88
- });
89
- ```
90
- See https://nitro.unjs.io/deploy/providers/aws for more details.
91
- 2. Remove `"type": "module"` from your `package.json` file, if it exists.
92
- This is required to make the CDK stack work. Click [here](https://github.com/ferdinandfrank/cdk-nuxt/issues/3) for details.
93
- 3. [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 7.
94
- 4. [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 7.
95
- 5. [Request a public **regional** 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 your desired region, e.g., `eu-central-1`, and validate it, if you don't have one yet.<br/>This is required to make the Nuxt app accessible via the custom domain and to provide the custom domain to the Nuxt app via the 'Host' header for server side rendering use cases.<br/>Take note of the displayed `ARN` for the certificate. You will need it in step 7.
96
- 6. [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 7.<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.**
97
- 7. 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 3), `hostedZoneId` (setup step 4), `regionalTlsCertificateArn` (setup step 5) and `globalTlsCertificateArn` (setup step 6).
98
-
99
- ```bash
100
- node_modules/.bin/cdk-nuxt-init-server
101
- ```
102
-
103
- > :warning: It's recommended using a `.env` file or another secrets file to import the sensitive secrets into the `stack/index.ts` file.
104
-
105
- ## Configuration
106
-
107
- The `NuxtServerAppStack` construct can be configured via the following props:
108
-
109
- ### project: string
110
- A string identifier for the project the Nuxt app is part of.
111
- A project might have multiple different services.
112
-
113
- ### service: string
114
- A string identifier for the project's service the Nuxt app is created for.
115
- This can be seen as the name of the Nuxt app.
116
-
117
- ### environment: string
118
- A string to identify the environment of the Nuxt app. This enables us
119
- to deploy multiple different environments of the same Nuxt app, e.g., production and development.
120
-
121
- ### domain: string
122
- The domain (without the protocol) at which the Nuxt app shall be publicly available.
123
- A DNS record will be automatically created in Route53 for the domain.
124
- This also supports subdomains.
125
- Examples: "example.com", "sub.example.com"
126
-
127
- ### hostedZoneId: string
128
- The id of the hosted zone to create a DNS record for the specified domain.
129
-
130
- ### globalTlsCertificateArn: string
131
- The ARN of the certificate to use on CloudFront for the Nuxt app to make it accessible via HTTPS.
132
- The certificate must be issued for the specified domain in us-east-1 (global) regardless of the
133
- region specified via 'env.region' as CloudFront only works globally.
134
-
135
- ### regionalTlsCertificateArn: string
136
- The ARN of the certificate to use at the ApiGateway for the Nuxt app to make it accessible via the custom domain
137
- and to provide the custom domain to the Nuxt app via the 'Host' header for server side rendering use cases.
138
- The certificate must be issued in the same region as specified via 'env.region' as ApiGateway works regionally.
139
-
140
- ### rootDir?: string;
141
- The path to the root directory of the Nuxt app (at which the `nuxt.config.ts` file is located).
142
- Defaults to '.'.
143
-
144
- ### entrypoint?: string
145
- The file name (without extension) of the Lambda entrypoint within the 'server' directory exporting a handler.
146
- Defaults to "index".
147
-
148
- ### entrypointEnv?: string
149
- A JSON serialized string of environment variables to pass to the Lambda function.
150
-
151
- ### memorySize?: number
152
- The memory size to apply to the Nuxt app's Lambda.
153
- Defaults to 1792MB (optimized for costs and performance for standard Nuxt apps).
154
-
155
- ### enableTracing?: boolean
156
- Whether to enable AWS X-Ray for the Nuxt Lambda function.
157
-
158
- ### enableApi?: boolean
159
- Whether to enable (HTTPS only) API access to the Nuxt app via the `/api` path which support all HTTP methods.
160
- See https://nuxt.com/docs/guide/directory-structure/server#recipes for details.
161
-
162
- ### enableSitemap?: boolean
163
- Whether to enable a global Sitemap bucket which is permanently accessible through multiple deployments.
164
-
165
- ### serverRoutes?: string[]
166
- An array of path patterns for server endpoints that should be routed to the SSR origin (API Gateway → Lambda) instead of the default S3 "file" behavior.
167
-
168
- This is useful for server routes that generate dynamic content but use file-like URLs. For example:
169
- - `@nuxtjs/sitemap` creates a `/sitemap.xml` endpoint that dynamically generates XML content
170
- - `@nuxt/image` uses file-like URLs (e.g., `/_ipx/*`) to serve dynamically processed images
171
-
172
- These patterns will be registered as CloudFront behaviors before the generic file-matching behavior, ensuring they take precedence.
173
-
174
- Examples: `['/sitemap.xml', '/robots.txt', '/__sitemap__/*', '/_ipx/*']`
175
-
176
- **Note:** This is different from `enableSitemap` which serves pre-generated static sitemap files from S3. Use `serverRoutes` when you need the Lambda to handle requests and generate content on-the-fly.
64
+ ### 2. Configure Nuxt
177
65
 
178
- ### enableAccessLogsAnalysis?: boolean
179
- Whether to enable access logs analysis for the Nuxt app's CloudFront distribution via Athena.
66
+ Set the Nitro preset in your `nuxt.config.ts`:
180
67
 
181
- ### accessLogCookies?: string[]
182
- An array of cookies to include for reporting in the access logs analysis.
183
- Only has an effect when `enableAccessLogsAnalysis` is set to `true`.
184
-
185
- ### outdatedAssetsRetentionDays?: number
186
- The number of days to retain static assets of outdated deployments in the S3 bucket.
187
- Useful to allow users to still access old assets after a new deployment when they are still browsing on an old version.
188
- Defaults to 30 days.
189
-
190
- ### forwardHeaders?: string[]
191
- An array of HTTP headers to forward to the Nuxt app on origin requests without affecting the cache key at CloudFront edge locations.
192
- This should only be used for headers that do not affect the response.
193
-
194
- No headers are forwarded by default.
195
-
196
- ### cacheKeyHeaders?: string[]
197
- An array of HTTP headers to forward to the Nuxt app and to include in the cache key for objects that are cached at CloudFront edge locations.
198
- This should be used for headers that might affect the response, e.g., 'Authorization'.
199
-
200
- No headers are forwarded or included in the cache key by default.
201
-
202
- ### forwardCookies?: string[]
203
- An array of cookies to forward to the Nuxt app on origin requests without affecting the cache key at CloudFront edge locations.
204
- This should only be used for cookies that do not affect the response.
68
+ ```typescript
69
+ export default defineNuxtConfig({
70
+ nitro: {
71
+ preset: 'aws-lambda'
72
+ },
73
+ });
74
+ ```
205
75
 
206
- No cookies are forwarded by default.
76
+ **Important:** Remove `"type": "module"` from your `package.json` if present ([why?](https://github.com/ferdinandfrank/cdk-nuxt/issues/3)).
207
77
 
208
- ### cacheKeyCookies?: string[]
209
- An array of cookies to forward to the Nuxt app and to include in the cache key for objects that are cached at CloudFront edge locations.
210
- This should be used for cookies that might affect the response, e.g., authentication cookies.
78
+ ### 3. AWS Prerequisites
211
79
 
212
- No cookies are forwarded or included in the cache key by default.
80
+ Before deployment, you need:
213
81
 
214
- ### forwardQueryParams?: string[]
215
- An array of query params to forward to the Nuxt app on origin requests without affecting the cache key at CloudFront edge locations.
216
- This should only be used for query params that do not affect the response and are required on SSR requests.
82
+ 1. **AWS Account** - [Create one](https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/) if you don't have one
83
+ 2. **Route53 Hosted Zone** - For your domain ([guide](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/AboutHZWorkingWith.html))
84
+ 3. **SSL Certificates** - Two certificates for HTTPS:
85
+ - **Global certificate** (us-east-1) for CloudFront ([request](https://docs.aws.amazon.com/acm/latest/userguide/gs-acm-request-public.html))
86
+ - **Regional certificate** (your region) for API Gateway ([request](https://docs.aws.amazon.com/acm/latest/userguide/gs-acm-request-public.html))
217
87
 
218
- All query params are forwarded by default.
88
+ ### 4. Initialize CDK Stack
219
89
 
220
- ### cacheKeyQueryParams?: string[]
221
- An array of query params to forward to the Nuxt app and to include in the cache key for objects that are cached at CloudFront edge locations.
222
- This should be used for query params that affect the response and are required on SSR requests, e.g., filters.
90
+ Generate the CDK stack configuration:
223
91
 
224
- All query params are forwarded and included in the cache key by default.
92
+ ```bash
93
+ node_modules/.bin/cdk-nuxt-init-server
94
+ ```
225
95
 
226
- ### denyCacheKeyQueryParams?: string[]
227
- An array of query params to prevent forwarding to the Nuxt app and to not include in the cache key for objects that are cached at CloudFront edge locations.
228
- When set, all query params that are not specified in this array will be forwarded to the Nuxt app and included in the cache key.
229
- This should be used for query params that do not affect the response and are not required on SSR requests, e.g., 'fbclid' or 'utm_campaign'.
96
+ This creates `stack/index.ts` with a complete template including all available configuration options with sensible defaults.
230
97
 
231
- If both `cacheKeyQueryParams` and `denyCacheKeyQueryParams` are specified, the `denyCacheKeyQueryParams` will be ignored.
232
- All query params are forwarded and included in the cache key by default.
98
+ **Update the following required values:**
99
+ - `env.account` and `env.region` - Your AWS account and region
100
+ - `project`, `service`, `environment` - Identifiers for your app
101
+ - `domain` - Your custom domain
102
+ - `hostedZoneId` - Your Route53 hosted zone ID
103
+ - `globalTlsCertificateArn` - Certificate in us-east-1 for CloudFront
104
+ - `regionalTlsCertificateArn` - Certificate in your region for API Gateway
233
105
 
106
+ The full template can also be viewed here: [lib/templates/stack-index-server.ts](lib/templates/stack-index-server.ts)
234
107
 
235
- ## Deployment
108
+ For a complete list of all configuration options, see the [Configuration Reference](docs/CONFIGURATION.md).
236
109
 
237
- 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
238
- by following the steps below:
110
+ > 💡 **Tip:** Use environment variables or a `.env` file to store sensitive values like certificate ARNs and AWS account IDs.
239
111
 
240
- ### 1. Bootstrap CDK
241
- Deploying stacks with the AWS CDK requires dedicated Amazon S3 buckets and other containers to be available to AWS CloudFormation during deployment.
242
- Creating this is called bootstrapping and is **only required once** per account and region.
243
- To bootstrap, run the following command:
112
+ ### 5. Bootstrap and Deploy
244
113
 
114
+ First-time setup (once per AWS account/region):
245
115
  ```bash
246
- cdk bootstrap aws://ACCOUNT-NUMBER/REGION
116
+ cdk bootstrap aws://YOUR_ACCOUNT_ID/YOUR_REGION
247
117
  ```
248
118
 
249
- See https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html for details.
250
-
251
- ### 2. Build and Deploy
252
-
253
- By running the following script, the Nuxt app will be built (using your package manager's `build` script)
254
- and the CDK stack will be deployed to AWS.
255
-
119
+ Deploy your app:
256
120
  ```bash
257
121
  node_modules/.bin/cdk-nuxt-deploy-server
258
122
  ```
259
123
 
260
- Alternatively, you can run the following commands separately to customize the deployment process. Choose your package manager:
124
+ That's it! Your Nuxt app is now live on AWS. 🎉
125
+
126
+ For detailed deployment options and CI/CD setup, see the [Deployment Guide](docs/DEPLOYMENT.md).
127
+
128
+ ## AWS Resources Created
129
+
130
+ When you deploy your Nuxt app, the following AWS resources are automatically created:
131
+
132
+ - **Lambda Functions:**
133
+ - Main SSR function for rendering your Nuxt app
134
+ - Lambda Layer for node_modules
135
+ - Cleanup function for outdated assets
136
+
137
+ - **S3 Buckets:**
138
+ - Static assets bucket (`.nuxt/dist/client`)
139
+ - Access logs bucket (if enabled)
140
+
141
+ - **CloudFront:**
142
+ - Global CDN distribution with HTTPS
143
+ - Optimized cache behaviors for static and dynamic content
144
+
145
+ - **API Gateway:**
146
+ - HTTP API for Lambda function access
147
+ - Custom domain configuration
148
+
149
+ - **Route53:**
150
+ - DNS records (A and AAAA) for your domain
151
+
152
+ - **EventBridge Rules:**
153
+ - Lambda warming (every 5 minutes)
154
+ - Asset cleanup (weekly, Tuesdays at 03:30 GMT)
155
+
156
+ - **Athena (optional):**
157
+ - Database and tables for access log analysis
158
+ - Automatic log partitioning
159
+
160
+ - **WAF (optional):**
161
+ - Web Application Firewall for CloudFront distribution
162
+ - Protection against common web exploits, bots, and DDoS attacks
163
+ - Configurable managed rules and rate limiting
164
+
165
+ For more details on each resource and their configuration, see the [Deployment Guide](docs/DEPLOYMENT.md).
166
+
167
+ ## Documentation
168
+
169
+ ### Getting Started
170
+ - [Quick Start](#quick-start) - Get up and running quickly
171
+ - [Deployment Guide](docs/DEPLOYMENT.md) - Detailed deployment instructions, CI/CD setup
172
+ - [Configuration Reference](docs/CONFIGURATION.md) - Complete list of all configuration options
173
+
174
+ ### Features
175
+ - [WAF Integration](docs/WAF.md) - Protect your app with AWS WAF
176
+ - [Access Logs Analysis](docs/ACCESS_LOGS.md) - Analyze traffic with Athena
177
+ - [Caching Configuration](docs/CACHING.md) - Optimize performance with CloudFront caching
178
+
179
+ ### Advanced
180
+ - [Destroy the Stack](#destroy-the-stack) - Clean up resources
261
181
 
262
- Using pnpm:
263
- ```bash
264
- pnpm build
265
- pnpm cdk deploy --require-approval never --all --app="pnpm ts-node stack/index.ts"
266
- ```
182
+ ## Destroy the Stack
267
183
 
268
- Using npm:
269
- ```bash
270
- npm run build
271
- npx cdk deploy --require-approval never --all --app="npx ts-node stack/index.ts"
272
- ```
184
+ To completely remove all AWS resources created by this package:
273
185
 
274
- Using Yarn:
275
186
  ```bash
276
- yarn build
277
- yarn cdk deploy --require-approval never --all --app="yarn ts-node stack/index.ts"
187
+ node_modules/.bin/cdk-nuxt-destroy-server
278
188
  ```
279
189
 
280
- #### Deploy with a custom TypeScript configuration
281
- Depending on your Nuxt app's TypeScript configuration and the setup of your stack, you might need a different TypeScript configuration for the CDK stack.
282
- You can do so by creating a `tsconfig.cdk.json` file in the root directory of your project and adjust the deployment command accordingly (choose your package manager):
190
+ ⚠️ **Warning:** This permanently deletes all resources including S3 buckets and logs. This action cannot be undone.
283
191
 
284
- Using pnpm:
285
- ```bash
286
- pnpm build
287
- pnpm cdk deploy --require-approval never --all --app="pnpm ts-node --project=tsconfig.cdk.json stack/index.ts"
288
- ```
192
+ ## Contributing
289
193
 
290
- Using npm:
291
- ```bash
292
- npm run build
293
- npx cdk deploy --require-approval never --all --app="npx ts-node --project=tsconfig.cdk.json stack/index.ts"
294
- ```
194
+ Contributions are welcome! Please feel free to submit a Pull Request.
295
195
 
296
- Using Yarn:
297
- ```bash
298
- yarn build
299
- yarn cdk deploy --require-approval never --all --app="yarn ts-node --project=tsconfig.cdk.json stack/index.ts"
300
- ```
196
+ ## License
301
197
 
302
- ## Destroy the Stack
198
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
303
199
 
304
- If you want to destroy the stack and all its resources (including storage, e.g., access logs), run the following script:
200
+ ## Support
305
201
 
306
- ```bash
307
- node_modules/.bin/cdk-nuxt-destroy-server
308
- ```
309
-
310
- ## Reference: Created AWS Resources
311
-
312
- In the following, you can find an overview of the AWS resources that will be created by this package for reference.
313
-
314
- ### NuxtServerAppStack
315
-
316
- This stack is responsible for deploying dynamic Nuxt apps to AWS.
317
- This stack will create the following AWS resources:
318
-
319
- - [Lambda](https://aws.amazon.com/lambda/):
320
- - 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.
321
- - A Lambda function that deletes the outdated static assets of the Nuxt app from S3.
322
- - [S3](https://aws.amazon.com/s3/):
323
- - A bucket to store the client files and static assets of the Nuxt build (`.nuxt/dist/client`) with optimized cache settings.
324
- - A bucket to store the CloudFront access logs for analysis via Athena. Only created if `enableAccessLogsAnalysis` is set to `true`.
325
- - [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.
326
- - [API Gateway](https://aws.amazon.com/api-gateway/): An HTTP API to make the Nuxt Lambda function publicly available.
327
- - [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.
328
- - [EventBridge](https://aws.amazon.com/eventbridge/):
329
- - 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.
330
- - 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.
331
- - [Athena](https://aws.amazon.com/athena/): A database and table to analyze the access logs of the Nuxt app's CloudFront distribution. Only created if `enableAccessLogsAnalysis` is set to `true`.
332
-
333
- ## Guidelines
334
-
335
- In the following, you can find some guidelines for the deployment and usages of this package.
336
-
337
- ### Automatically deploy on every push (CD) via [GitHub Actions](https://github.com/features/actions)
338
-
339
- 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.
340
-
341
- ```yaml
342
- name: Deploy
343
-
344
- on:
345
- push:
346
- branches:
347
- - master # Feel free to use another branch name
348
-
349
- jobs:
350
- build:
351
- runs-on: ubuntu-latest
352
- steps:
353
- - name: Checkout source code
354
- uses: actions/checkout@v4
355
-
356
- # Enable if using Yarn >= 2
357
- # - name: Enable Corepack for Yarn
358
- # run: corepack enable
359
-
360
- - name: Configure Node.js
361
- uses: actions/setup-node@v4
362
- with:
363
- node-version: '20'
364
- cache: 'pnpm' # or 'yarn' or 'npm'
365
-
366
- - name: Install dependencies
367
- run: |
368
- pnpm install --frozen-lockfile
369
- # or: npm ci
370
- # or: yarn install --frozen-lockfile # or `yarn install --immutable` for Yarn >= 2
371
-
372
- - name: Build and deploy to AWS
373
- run: node_modules/.bin/cdk-nuxt-deploy-server # Or run a customized deployment, see 'Build and Deploy' section
374
- env:
375
- # Create an IAM user on AWS for the deployment and create the appropriate secrets in the GitHub repository secrets
376
- AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
377
- AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
378
- AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
379
- ```
202
+ - 📖 [Documentation](docs/)
203
+ - 🐛 [Issue Tracker](https://github.com/ferdinandfrank/cdk-nuxt/issues)
204
+ - 💬 [Discussions](https://github.com/ferdinandfrank/cdk-nuxt/discussions)
package/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  export { NuxtServerAppStack } from "./lib/stack/server/NuxtServerAppStack";
2
2
  export { NuxtServerAppStackProps } from "./lib/stack/server/NuxtServerAppStackProps";
3
+ export type { WafConfig } from "./lib/stack/waf/WafConfig";
4
+ export { DEFAULT_NUXT_WAF_CONFIG } from "./lib/stack/waf/WafConfig";
5
+ export { CloudFrontWebAcl } from "./lib/stack/waf/CloudFrontWebAcl";
3
6
  export { App } from "aws-cdk-lib";
package/index.js CHANGED
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.App = exports.NuxtServerAppStack = void 0;
3
+ exports.App = exports.CloudFrontWebAcl = exports.DEFAULT_NUXT_WAF_CONFIG = exports.NuxtServerAppStack = void 0;
4
4
  var NuxtServerAppStack_1 = require("./lib/stack/server/NuxtServerAppStack");
5
5
  Object.defineProperty(exports, "NuxtServerAppStack", { enumerable: true, get: function () { return NuxtServerAppStack_1.NuxtServerAppStack; } });
6
+ var WafConfig_1 = require("./lib/stack/waf/WafConfig");
7
+ Object.defineProperty(exports, "DEFAULT_NUXT_WAF_CONFIG", { enumerable: true, get: function () { return WafConfig_1.DEFAULT_NUXT_WAF_CONFIG; } });
8
+ var CloudFrontWebAcl_1 = require("./lib/stack/waf/CloudFrontWebAcl");
9
+ Object.defineProperty(exports, "CloudFrontWebAcl", { enumerable: true, get: function () { return CloudFrontWebAcl_1.CloudFrontWebAcl; } });
6
10
  var aws_cdk_lib_1 = require("aws-cdk-lib");
7
11
  Object.defineProperty(exports, "App", { enumerable: true, get: function () { return aws_cdk_lib_1.App; } });
8
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSw0RUFBd0U7QUFBaEUsd0hBQUEsa0JBQWtCLE9BQUE7QUFFMUIsMkNBQWdDO0FBQXhCLGtHQUFBLEdBQUcsT0FBQSIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCB7TnV4dFNlcnZlckFwcFN0YWNrfSBmcm9tIFwiLi9saWIvc3RhY2svc2VydmVyL051eHRTZXJ2ZXJBcHBTdGFja1wiXG5leHBvcnQge051eHRTZXJ2ZXJBcHBTdGFja1Byb3BzfSBmcm9tIFwiLi9saWIvc3RhY2svc2VydmVyL051eHRTZXJ2ZXJBcHBTdGFja1Byb3BzXCJcbmV4cG9ydCB7QXBwfSBmcm9tIFwiYXdzLWNkay1saWJcIjsiXX0=
12
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSw0RUFBd0U7QUFBaEUsd0hBQUEsa0JBQWtCLE9BQUE7QUFHMUIsdURBQWlFO0FBQXpELG9IQUFBLHVCQUF1QixPQUFBO0FBQy9CLHFFQUFpRTtBQUF6RCxvSEFBQSxnQkFBZ0IsT0FBQTtBQUN4QiwyQ0FBZ0M7QUFBeEIsa0dBQUEsR0FBRyxPQUFBIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IHtOdXh0U2VydmVyQXBwU3RhY2t9IGZyb20gXCIuL2xpYi9zdGFjay9zZXJ2ZXIvTnV4dFNlcnZlckFwcFN0YWNrXCJcbmV4cG9ydCB7TnV4dFNlcnZlckFwcFN0YWNrUHJvcHN9IGZyb20gXCIuL2xpYi9zdGFjay9zZXJ2ZXIvTnV4dFNlcnZlckFwcFN0YWNrUHJvcHNcIlxuZXhwb3J0IHR5cGUge1dhZkNvbmZpZ30gZnJvbSBcIi4vbGliL3N0YWNrL3dhZi9XYWZDb25maWdcIlxuZXhwb3J0IHtERUZBVUxUX05VWFRfV0FGX0NPTkZJR30gZnJvbSBcIi4vbGliL3N0YWNrL3dhZi9XYWZDb25maWdcIlxuZXhwb3J0IHtDbG91ZEZyb250V2ViQWNsfSBmcm9tIFwiLi9saWIvc3RhY2svd2FmL0Nsb3VkRnJvbnRXZWJBY2xcIlxuZXhwb3J0IHtBcHB9IGZyb20gXCJhd3MtY2RrLWxpYlwiOyJdfQ==
@@ -87,6 +87,12 @@ export declare class NuxtServerAppStack extends Stack {
87
87
  * @private
88
88
  */
89
89
  private readonly cdn;
90
+ /**
91
+ * The AWS WAF Web ACL to protect the CloudFront distribution (optional).
92
+ *
93
+ * @private
94
+ */
95
+ private webAcl;
90
96
  constructor(scope: Construct, id: string, props: NuxtServerAppStackProps);
91
97
  /**
92
98
  * Creates the current deployment revision file in the public folder of the Nuxt app to be accessible