cdk-nuxt 2.14.0 → 2.18.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/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,358 +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
- ### enableAccessLogsAnalysis?: boolean
166
- Whether to enable access logs analysis for the Nuxt app's CloudFront distribution via Athena.
167
-
168
- ### accessLogCookies?: string[]
169
- An array of cookies to include for reporting in the access logs analysis.
170
- Only has an effect when `enableAccessLogsAnalysis` is set to `true`.
171
-
172
- ### outdatedAssetsRetentionDays?: number
173
- The number of days to retain static assets of outdated deployments in the S3 bucket.
174
- Useful to allow users to still access old assets after a new deployment when they are still browsing on an old version.
175
- Defaults to 30 days.
64
+ ### 2. Configure Nuxt
176
65
 
177
- ### forwardHeaders?: string[]
178
- An array of HTTP headers to forward to the Nuxt app on origin requests without affecting the cache key at CloudFront edge locations.
179
- This should only be used for headers that do not affect the response.
66
+ Set the Nitro preset in your `nuxt.config.ts`:
180
67
 
181
- No headers are forwarded by default.
182
-
183
- ### cacheKeyHeaders?: string[]
184
- 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.
185
- This should be used for headers that might affect the response, e.g., 'Authorization'.
186
-
187
- No headers are forwarded or included in the cache key by default.
188
-
189
- ### forwardCookies?: string[]
190
- An array of cookies to forward to the Nuxt app on origin requests without affecting the cache key at CloudFront edge locations.
191
- 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
+ ```
192
75
 
193
- 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)).
194
77
 
195
- ### cacheKeyCookies?: string[]
196
- 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.
197
- This should be used for cookies that might affect the response, e.g., authentication cookies.
78
+ ### 3. AWS Prerequisites
198
79
 
199
- No cookies are forwarded or included in the cache key by default.
80
+ Before deployment, you need:
200
81
 
201
- ### forwardQueryParams?: string[]
202
- An array of query params to forward to the Nuxt app on origin requests without affecting the cache key at CloudFront edge locations.
203
- 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))
204
87
 
205
- All query params are forwarded by default.
88
+ ### 4. Initialize CDK Stack
206
89
 
207
- ### cacheKeyQueryParams?: string[]
208
- 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.
209
- 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:
210
91
 
211
- All query params are forwarded and included in the cache key by default.
92
+ ```bash
93
+ node_modules/.bin/cdk-nuxt-init-server
94
+ ```
212
95
 
213
- ### denyCacheKeyQueryParams?: string[]
214
- 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.
215
- 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.
216
- 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.
217
97
 
218
- If both `cacheKeyQueryParams` and `denyCacheKeyQueryParams` are specified, the `denyCacheKeyQueryParams` will be ignored.
219
- 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
220
105
 
106
+ The full template can also be viewed here: [lib/templates/stack-index-server.ts](lib/templates/stack-index-server.ts)
221
107
 
222
- ## Deployment
108
+ For a complete list of all configuration options, see the [Configuration Reference](docs/CONFIGURATION.md).
223
109
 
224
- 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
225
- 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.
226
111
 
227
- ### 1. Bootstrap CDK
228
- Deploying stacks with the AWS CDK requires dedicated Amazon S3 buckets and other containers to be available to AWS CloudFormation during deployment.
229
- Creating this is called bootstrapping and is **only required once** per account and region.
230
- To bootstrap, run the following command:
112
+ ### 5. Bootstrap and Deploy
231
113
 
114
+ First-time setup (once per AWS account/region):
232
115
  ```bash
233
- cdk bootstrap aws://ACCOUNT-NUMBER/REGION
116
+ cdk bootstrap aws://YOUR_ACCOUNT_ID/YOUR_REGION
234
117
  ```
235
118
 
236
- See https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html for details.
237
-
238
- ### 2. Build and Deploy
239
-
240
- By running the following script, the Nuxt app will be built (using your package manager's `build` script)
241
- and the CDK stack will be deployed to AWS.
242
-
119
+ Deploy your app:
243
120
  ```bash
244
121
  node_modules/.bin/cdk-nuxt-deploy-server
245
122
  ```
246
123
 
247
- 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
248
181
 
249
- Using pnpm:
250
- ```bash
251
- pnpm build
252
- pnpm cdk deploy --require-approval never --all --app="pnpm ts-node stack/index.ts"
253
- ```
182
+ ## Destroy the Stack
254
183
 
255
- Using npm:
256
- ```bash
257
- npm run build
258
- npx cdk deploy --require-approval never --all --app="npx ts-node stack/index.ts"
259
- ```
184
+ To completely remove all AWS resources created by this package:
260
185
 
261
- Using Yarn:
262
186
  ```bash
263
- yarn build
264
- yarn cdk deploy --require-approval never --all --app="yarn ts-node stack/index.ts"
187
+ node_modules/.bin/cdk-nuxt-destroy-server
265
188
  ```
266
189
 
267
- #### Deploy with a custom TypeScript configuration
268
- 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.
269
- 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.
270
191
 
271
- Using pnpm:
272
- ```bash
273
- pnpm build
274
- pnpm cdk deploy --require-approval never --all --app="pnpm ts-node --project=tsconfig.cdk.json stack/index.ts"
275
- ```
192
+ ## Contributing
276
193
 
277
- Using npm:
278
- ```bash
279
- npm run build
280
- npx cdk deploy --require-approval never --all --app="npx ts-node --project=tsconfig.cdk.json stack/index.ts"
281
- ```
194
+ Contributions are welcome! Please feel free to submit a Pull Request.
282
195
 
283
- Using Yarn:
284
- ```bash
285
- yarn build
286
- yarn cdk deploy --require-approval never --all --app="yarn ts-node --project=tsconfig.cdk.json stack/index.ts"
287
- ```
196
+ ## License
288
197
 
289
- ## Destroy the Stack
290
-
291
- If you want to destroy the stack and all its resources (including storage, e.g., access logs), run the following script:
198
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
292
199
 
293
- ```bash
294
- node_modules/.bin/cdk-nuxt-destroy-server
295
- ```
200
+ ## Support
296
201
 
297
- ## Reference: Created AWS Resources
298
-
299
- In the following, you can find an overview of the AWS resources that will be created by this package for reference.
300
-
301
- ### NuxtServerAppStack
302
-
303
- This stack is responsible for deploying dynamic Nuxt apps to AWS.
304
- This stack will create the following AWS resources:
305
-
306
- - [Lambda](https://aws.amazon.com/lambda/):
307
- - 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.
308
- - A Lambda function that deletes the outdated static assets of the Nuxt app from S3.
309
- - [S3](https://aws.amazon.com/s3/):
310
- - A bucket to store the client files and static assets of the Nuxt build (`.nuxt/dist/client`) with optimized cache settings.
311
- - A bucket to store the CloudFront access logs for analysis via Athena. Only created if `enableAccessLogsAnalysis` is set to `true`.
312
- - [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.
313
- - [API Gateway](https://aws.amazon.com/api-gateway/): An HTTP API to make the Nuxt Lambda function publicly available.
314
- - [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.
315
- - [EventBridge](https://aws.amazon.com/eventbridge/):
316
- - 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.
317
- - 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.
318
- - [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`.
319
-
320
- ## Guidelines
321
-
322
- In the following, you can find some guidelines for the deployment and usages of this package.
323
-
324
- ### Automatically deploy on every push (CD) via [GitHub Actions](https://github.com/features/actions)
325
-
326
- 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.
327
-
328
- ```yaml
329
- name: Deploy
330
-
331
- on:
332
- push:
333
- branches:
334
- - master # Feel free to use another branch name
335
-
336
- jobs:
337
- build:
338
- runs-on: ubuntu-latest
339
- steps:
340
- - name: Checkout source code
341
- uses: actions/checkout@v4
342
-
343
- # Enable if using Yarn >= 2
344
- # - name: Enable Corepack for Yarn
345
- # run: corepack enable
346
-
347
- - name: Configure Node.js
348
- uses: actions/setup-node@v4
349
- with:
350
- node-version: '20'
351
- cache: 'pnpm' # or 'yarn' or 'npm'
352
-
353
- - name: Install dependencies
354
- run: |
355
- pnpm install --frozen-lockfile
356
- # or: npm ci
357
- # or: yarn install --frozen-lockfile # or `yarn install --immutable` for Yarn >= 2
358
-
359
- - name: Build and deploy to AWS
360
- run: node_modules/.bin/cdk-nuxt-deploy-server # Or run a customized deployment, see 'Build and Deploy' section
361
- env:
362
- # Create an IAM user on AWS for the deployment and create the appropriate secrets in the GitHub repository secrets
363
- AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
364
- AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
365
- AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
366
- ```
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
@@ -161,6 +167,12 @@ export declare class NuxtServerAppStack extends Stack {
161
167
  * Creates a behavior for the CloudFront distribution to route matching Nuxt app API requests to the API gateway.
162
168
  */
163
169
  private createApiRouteBehavior;
170
+ /**
171
+ * Creates behaviors for the CloudFront distribution to route specified path patterns to the SSR origin.
172
+ * This allows server endpoints that use file-like URLs (e.g., /sitemap.xml from @nuxtjs/sitemap)
173
+ * to be handled by the Lambda function for dynamic content generation.
174
+ */
175
+ private createServerRouteBehavior;
164
176
  /**
165
177
  * Creates a behavior for the CloudFront distribution to route matching incoming requests for the static assets
166
178
  * to the S3 bucket that holds these static assets.