cloudfrontize 1.1.7 → 1.3.0

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.
Files changed (33) hide show
  1. package/README.md +141 -83
  2. package/dist/cli.js +36 -32
  3. package/dist/ui/app.js +399 -0
  4. package/dist/ui/favicons/android-icon-144x144.png +0 -0
  5. package/dist/ui/favicons/android-icon-192x192.png +0 -0
  6. package/dist/ui/favicons/android-icon-36x36.png +0 -0
  7. package/dist/ui/favicons/android-icon-48x48.png +0 -0
  8. package/dist/ui/favicons/android-icon-72x72.png +0 -0
  9. package/dist/ui/favicons/android-icon-96x96.png +0 -0
  10. package/dist/ui/favicons/apple-icon-114x114.png +0 -0
  11. package/dist/ui/favicons/apple-icon-120x120.png +0 -0
  12. package/dist/ui/favicons/apple-icon-144x144.png +0 -0
  13. package/dist/ui/favicons/apple-icon-152x152.png +0 -0
  14. package/dist/ui/favicons/apple-icon-180x180.png +0 -0
  15. package/dist/ui/favicons/apple-icon-57x57.png +0 -0
  16. package/dist/ui/favicons/apple-icon-60x60.png +0 -0
  17. package/dist/ui/favicons/apple-icon-72x72.png +0 -0
  18. package/dist/ui/favicons/apple-icon-76x76.png +0 -0
  19. package/dist/ui/favicons/apple-icon-precomposed.png +0 -0
  20. package/dist/ui/favicons/apple-icon.png +0 -0
  21. package/dist/ui/favicons/browserconfig.xml +11 -0
  22. package/dist/ui/favicons/favicon-16x16.png +0 -0
  23. package/dist/ui/favicons/favicon-32x32.png +0 -0
  24. package/dist/ui/favicons/favicon-96x96.png +0 -0
  25. package/dist/ui/favicons/favicon.ico +0 -0
  26. package/dist/ui/favicons/manifest.json +41 -0
  27. package/dist/ui/favicons/ms-icon-144x144.png +0 -0
  28. package/dist/ui/favicons/ms-icon-150x150.png +0 -0
  29. package/dist/ui/favicons/ms-icon-310x310.png +0 -0
  30. package/dist/ui/favicons/ms-icon-70x70.png +0 -0
  31. package/dist/ui/index.html +102 -0
  32. package/dist/ui/style.css +639 -0
  33. package/package.json +1 -1
package/README.md CHANGED
@@ -1,10 +1,74 @@
1
1
  # cloudfrontize
2
+
2
3
  [![Sponsor](https://img.shields.io/badge/Sponsor-❤️-ff69b4?style=for-the-badge&logo=github)](https://github.com/sponsors/felipecarrillo100)
4
+ ![npm](https://img.shields.io/npm/v/cloudfrontize)
5
+ ![node](https://img.shields.io/node/v/cloudfrontize)
6
+
7
+ 📜 **Changelog:** See [CHANGELOG.md](CHANGELOG.md) for release history.
8
+
9
+ ---
10
+
11
+ #### A high-fidelity local development server for AWS Lambda@Edge and CloudFront Functions.
12
+
13
+ Test your Edge logic locally in milliseconds instead of waiting 15 minutes for CloudFront deployments.
14
+
15
+ <div style="display: flex; justify-content: space-around; align-items: center;">
16
+ <img alt="Cloudfrontize Banner" src="https://raw.githubusercontent.com/felipecarrillo100/cloudfrontize/main/assets/cloudfrontize.png" width="45%" />
17
+ <img alt="Cloudfrontize Web UI" src="https://raw.githubusercontent.com/felipecarrillo100/cloudfrontize/main/assets/cloudfrontize-webui.jpg" width="45%" />
18
+ </div>
19
+
20
+ ---
21
+ ## 📦 Getting started
22
+ Get up and running in seconds. No complex AWS IAM roles, no stack traces—just your code, running locally.
23
+
24
+ ### Install **globally:**
25
+
26
+ ```bash
27
+ npm install -g cloudfrontize
28
+ ```
29
+ Once installed, you can run CloudFrontize from any directory: by simply typing `cloudfrontize ./www` (specifying your static folder).
30
+
31
+ Point it at your static files folder (`./www`, `./dist` or `./public`) and point to your Lambda@Edge `.js` file. CloudFrontize handles the rest.
32
+
33
+ ## ⚡ Quick Example
34
+
35
+ 1️⃣ Create a simple Lambda@Edge function, for instance: `viewer-request-rewrite.js`
36
+
37
+ ```javascript
38
+ exports.hookType = 'viewer-request';
39
+
40
+ exports.handler = (event, context, callback) => {
41
+ const request = event.Records[0].cf.request;
42
+ console.log("Original request", request.uri);
43
+ request.uri = "/index-alt.html";
44
+ callback(null, request);
45
+ };
46
+ ```
47
+
48
+ 2️⃣ Run CloudFrontize
49
+
50
+ ```
51
+ cloudfrontize ./www --edge ./viewer-request-rewrite.js --debug
52
+ ```
53
+ For this sample, place two HTML files inside the `www` folder: `index.html` and `index-alt.html`.
54
+
55
+ 3️⃣ Open
56
+
57
+ Open your browser and navigate to: http://localhost:3000
58
+
59
+ Because the `viewer-request` hook is active, every request is rewritten to `/index-alt.html`. As a result, the browser will display the contents of that file regardless of the requested path.
60
+
61
+ Check the CloudFrontize terminal output. You should see a log entry confirming the internal URI rewrite:
62
+ ```text
63
+ 2026-03-16T22:18:51.465Z [44ff0e42] [viewer-request] Original request /
64
+ [Debug] Mode: rest, isRestMode: true, URL: /index-alt.html, FullPath: C:\tmp\www\index-alt.html
65
+ ```
3
66
 
4
- A high-performance, high-fidelity local emulator for AWS Lambda@Edge and CloudFront Functions.
5
- ### 📣 Stop bowing to the deployment bar!
67
+ ---
68
+
69
+ ## 📣 Stop waiting for CloudFront deployments!
6
70
 
7
- **Rule the Edge** and become the Hero of the Cloud. **Escape the "Deploy-and-Pray" cycle.** We’ve all been there: you tweak one security header, hit "Deploy," and... **you wait.** For 15 agonizing minutes, you watch a spinning "In Progress" status as AWS propagates your code globally. If there’s a tiny typo? You won't know until you hit a **502 Bad Gateway** and go hunting through CloudWatch logs buried in a random region.
71
+ **Take control** of your Edge development workflow. **Escape the "Deploy-and-Pray" cycle.** We’ve all been there: you tweak one security header, hit "Deploy," and... **you wait.** For 15 agonizing minutes, you watch a spinning "In Progress" status as AWS propagates your code globally. If there’s a tiny typo? You won't know until you hit a **502 Bad Gateway** and go hunting through CloudWatch logs buried in a random region.
8
72
 
9
73
  It’s a workflow that kills momentum and turns "quick fixes" into afternoon-long ordeals.
10
74
 
@@ -26,7 +90,7 @@ The CloudFront/Lambda@Edge development loop is notoriously painful. Propagation
26
90
 
27
91
  **CloudFrontize** eliminates the wait and the risk:
28
92
 
29
- * **Zero-Config Integration:** If you know how to use Vercel's [serve](https://www.google.com/search?q=%5Bhttps://www.npmjs.com/package/serve%5D(https://www.npmjs.com/package/serve)) package, you already know how to use `cloudfrontize`.
93
+ * **Zero-Config Integration:** If you know how to use Vercel's [serve](https://www.npmjs.com/package/serve) package, you already know how to use `cloudfrontize`.
30
94
  * **Real-Time Hot Reloading:** Tweak your URI rewrites or security headers and see the results instantly on browser refresh. No packaging, no uploading, no waiting for the "In Progress" spinner.
31
95
  * **Debug directly to the console:** Stop hunting for logs in hidden CloudWatch streams across random regions. See your console.log outputs and execution errors live **in your terminal**.
32
96
  * **Production Fidelity:** Emulates in detail CloudFront-specific features & quirks, like the **10MB auto-compression limit**, header blacklisting, and URI normalization.
@@ -50,48 +114,11 @@ While tools like `serverless-offline` or `SAM CLI` are great for standard Lambda
50
114
 
51
115
  **CloudFrontize** is not just a runner; it's a **Linter at the Edge**, ensuring your code is valid *before* the 15-minute propagation wait.
52
116
 
53
-
54
- ---
55
-
56
- ## 📦 Install & Go
57
- Get up and running in seconds. No complex AWS IAM roles, no stack traces—just your code, running locally.
58
-
59
- ### Install it **Globally:**
60
-
61
- ```bash
62
- npm install -g cloudfrontize
63
- ```
64
- Once installed, you can rule the Edge from any directory by simply typing `cloudfrontize ./www` (specifying your static folder).
65
-
66
- Point it at your static files folder (`./www`, `./dist` or `./public`) and point to your Lambda@Edge `.js` file. CloudFrontize handles the rest.
67
-
68
- ```bash
69
- cloudfrontize ./folder --edge ./lambda-at-age-logic.js
70
- ```
71
- OR
72
- ```bash
73
- npx cloudfrontize ./folder --edge ./lambda-at-age-logic.js
74
- ```
75
-
76
- ---
77
-
78
- ## 🎓 CloudFrontize Academy (Tutorial)
79
-
80
- New to Lambda@Edge? We've built a comprehensive, hands-on tutorial to take you from **Newbie to Production Pro**.
81
-
82
- Our **[CloudFrontize Academy](./tutorial/README.md)** includes 10 thematic exercises covering:
83
- * **Module 1: Foundations** (Security Headers, Redirects, Normalization)
84
- * **Module 2: Origin Intelligence** (A/B Testing, Geo-Localization, Header Cleaning)
85
- * **Module 3: Edge Computing** (Custom Auth, Maintenance Pages, Payload Inspection)
86
- * **Module 4: Production Workflows** (Variable Baking & Deployment)
87
-
88
- Each exercise comes with a **Business Scenario**, **Starter Template**, and **Full Solution**.
89
-
90
117
  ---
91
118
 
92
119
  ## 🛠️ CLI Options & Configuration
93
120
 
94
- `cloudfrontize` is designed to be a drop-in replacement for the popular [serve](https://www.google.com/search?q=%5Bhttps://www.npmjs.com/package/serve%5D(https://www.npmjs.com/package/serve)), we all know and love, but with "Edge Superpowers!"
121
+ `cloudfrontize` is designed to be a drop-in replacement for the popular [serve](https://www.npmjs.com/package/serve), we all know and love, but with "Edge Superpowers!"
95
122
 
96
123
  | Flag | Description | Default |
97
124
  | --- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
@@ -105,6 +132,7 @@ Each exercise comes with a **Business Scenario**, **Starter Template**, and **Fu
105
132
  | **`-o, --output <path>`**| Output the baked `.js` file(s) for production deployment | `null` |
106
133
  | **`-p, --port <number>`** | Port to listen on | `3000` |
107
134
  | **`-l, --listen <uri>`** | Listen URI (overrides `--port`) | `3000` |
135
+ | **`--webui <port>`** | Enable the visual control plane for real-time traffic inspection and header debugging | `disabled` |
108
136
  | **`-s, --single`** | SPA mode — rewrite all 404s to `index.html` | `off` |
109
137
  | **`-C, --cors`** | Enable `Access-Control-Allow-Origin: *` | `off` |
110
138
  | **`-d, --debug`** | Show Lambda execution logs and URI rewrites | `off` |
@@ -116,6 +144,17 @@ Each exercise comes with a **Business Scenario**, **Starter Template**, and **Fu
116
144
 
117
145
  ---
118
146
 
147
+ ## 🖥️ Visual Control Plane (Web UI)
148
+
149
+ CloudFrontize includes an optional, browser-based UI to help you visualize your edge logic in real-time. Inspect headers, track URI rewrites, and debug Lambda@Edge execution without leaving your browser.
150
+
151
+ Using the **Header Intelligence** panel, you can inject or override headers on-the-fly to test Geo-routing, Auth tokens, or Security policies without changing a single line of code.
152
+
153
+ **[👉 Learn how to use the Web UI](docs/web-ui.md)**
154
+
155
+ ---
156
+
157
+
119
158
  ## 🚀 Lambda@Edge Integration
120
159
 
121
160
  Since there is no AWS CloudFront Console to configure your triggers locally, **it is mandatory to include `exports.hookType` in your JavaScript file.** If this line is missing, CloudFrontize will not know when to fire your function and will ignore the file.
@@ -139,27 +178,15 @@ When pointing `--cff` to a directory, files must follow a strict naming conventi
139
178
 
140
179
  Files within a directory are executed in **lexicographical order**.
141
180
 
142
- ### CFF Example (`viewer-request-redirect.js`)
181
+ ## 🛡️ Engineered for Fidelity
143
182
 
144
- ```javascript
145
- function handler(event) {
146
- var request = event.request;
147
- var uri = request.uri;
148
-
149
- // Direct response (short-circuits the pipeline)
150
- if (uri === '/old-path') {
151
- return {
152
- statusCode: 301,
153
- statusDescription: 'Moved Permanently',
154
- headers: {
155
- 'location': { value: '/new-path' }
156
- }
157
- };
158
- }
183
+ Don't just simulate the Edge—**master it.** CloudFrontize is built to mirror the high-stakes environment of a live AWS PoP (Point of Presence).
159
184
 
160
- return request;
161
- }
162
- ```
185
+ * **⚡ Native Async/Await Support:** Whether your middleware is a simple redirect or a complex, asynchronous database lookup, CloudFrontize handles `async` handlers and Promises with the same grace as the live Lambda@Edge runtime.
186
+ * **🧩 Multi-Hook Testing:** Pass a directory to `--edge` and CloudFrontize will automatically mount every valid Lambda it finds. Orchestrate your **Viewer Request**, **Origin Request**, and **Response** hooks in one unified local environment.
187
+ * **📦 RequestBody Access:** Use `event.Records[0].cf.request.body` to access base64 encoded payloads. We support the standard AWS buffering logic.
188
+ * **🚫 Strict Header & Body Validation:** Use `--strict` to identify "Read-only" or "Forbidden" headers for **both request and response hooks**, as well as the **40KB viewer-request body limit** and the **1MB generated response limit** in real-time. We trigger **502 Bad Gateway** errors locally for the same illegal mutations that fail in production.
189
+ * **🎭 Mocked Context & Events:** We provide a high-fidelity `event` and `context` object, ensuring your logging, metrics, and custom error-handling tools work exactly as they would in production.
163
190
 
164
191
  ---
165
192
 
@@ -168,19 +195,11 @@ function handler(event) {
168
195
 
169
196
  We’ve bundled a complete, interactive sample to show you the power of **CloudFrontize**. It protects a premium dog photography gallery using a `viewer-request` authentication gate.
170
197
 
171
- ### Launch the Secure Demo
198
+ ### Lambda@Edge sample
172
199
  Clone the GitHub repo
173
200
  ```shell
174
201
  git clone https://github.com/felipecarrillo100/cloudfrontize.git
175
202
  ```
176
- Then run
177
- ```bash
178
- cloudfrontize ./www -e ./samples/medium/lambda-edge-authorization.js -d -C
179
- ```
180
- * The `www` folder contains the sample files (html, js, css, etc.)
181
- * The `lambda-edge-authorization.js` contains the lambda@edge logic
182
- * The `-d` option enables debug messages while `-C` enables CORS
183
- * Default port is 3000, you can now open your browser at http://localhost:3000/
184
203
 
185
204
  ### The Sample Logic (`lambda-edge-authorization.js`)
186
205
 
@@ -200,7 +219,7 @@ exports.handler = (event, context, callback) => {
200
219
 
201
220
  // Credentials for demo purposes
202
221
  const user = "admin";
203
- const password = "pass";
222
+ const password = "password";
204
223
 
205
224
  const authString = "Basic " + Buffer.from(user + ":" + password).toString("base64");
206
225
 
@@ -227,29 +246,68 @@ exports.handler = (event, context, callback) => {
227
246
  callback(null, request);
228
247
  };
229
248
  ```
249
+ Then run
250
+ ```bash
251
+ cloudfrontize ./www -e ./samples/medium/lambda-edge-authorization.js -d -C
252
+ ```
253
+ * The `www` folder contains the sample files (html, js, css, etc.)
254
+ * The `lambda-edge-authorization.js` file contains the lambda@edge logic
255
+ * The `-d` option enables debug messages while `-C` enables CORS
256
+ * Default port is 3000, you can now open your browser at http://localhost:3000/
257
+ * The username is `admin` and the password is `password`, as defined in the Lambda@Edge logic.
258
+
259
+ ### A CFF Example
260
+ Your file must start with `viewer-request` or `viewer-response` to let the simulator know the type of CFF we want to execute. In this case we have called it: `viewer-request-redirect.js`
261
+ ```javascript
262
+ function handler(event) {
263
+ var request = event.request;
264
+ var uri = request.uri;
265
+
266
+ // Direct response (short-circuits the pipeline)
267
+ if (uri === '/promo') {
268
+ return {
269
+ statusCode: 301,
270
+ statusDescription: 'Moved Permanently',
271
+ headers: {
272
+ 'location': { value: '/summer-sale' }
273
+ }
274
+ };
275
+ }
276
+
277
+ return request;
278
+ }
279
+ ```
230
280
 
281
+ Run with:
282
+ ```bash
283
+ cloudfrontize ./www --cff ./samples/cff/viewer-request-redirect.js -d --mode website
284
+ ```
285
+ * `-d` Enables debug, and `--mode website` takes care of appending `index.html` to folders
286
+ * Open in browser http://localhost:3000/promo
287
+ * You will be redirected to http://localhost:3000/summer-sale
231
288
  ---
232
289
 
233
- ### 🛡️ Engineered for Fidelity
290
+ ## 🎓 CloudFrontize Academy (Tutorial)
234
291
 
235
- Don't just simulate the Edge—**master it.** CloudFrontize is built to mirror the high-stakes environment of a live AWS PoP (Point of Presence).
292
+ New to Lambda@Edge? We've built a comprehensive, hands-on tutorial to take you from **Newbie to Production Pro**.
236
293
 
237
- * **⚡ Native Async/Await Support:** Whether your middleware is a simple redirect or a complex, asynchronous database lookup, CloudFrontize handles `async` handlers and Promises with the same grace as the live Lambda@Edge runtime.
238
- * **🧩 Multi-Hook Testing:** Pass a directory to `--edge` and CloudFrontize will automatically mount every valid Lambda it finds. Orchestrate your **Viewer Request**, **Origin Request**, and **Response** hooks in one unified local environment.
239
- * **📦 RequestBody Access:** Use `event.Records[0].cf.request.body` to access base64 encoded payloads. We support the standard AWS buffering logic.
240
- * **🚫 Strict Header & Body Validation:** Use `--strict` to identify "Read-only" or "Forbidden" headers for **both request and response hooks**, as well as the **40KB viewer-request body limit** and the **1MB generated response limit** in real-time. We trigger **502 Bad Gateway** errors locally for the same illegal mutations that fail in production.
241
- * **🎭 Mocked Context & Events:** We provide a high-fidelity `event` and `context` object, ensuring your logging, metrics, and custom error-handling tools work exactly as they would in production.
294
+ Our **[CloudFrontize Academy](./tutorial/README.md)** includes 20+ thematic exercises covering:
295
+ * **Module 1: Foundations** (Security Headers, Redirects, Normalization)
296
+ * **Module 2: Origin Intelligence** (A/B Testing, Geo-Localization, Header Cleaning)
297
+ * **Module 3: Edge Computing** (Custom Auth, Maintenance Pages, Payload Inspection)
298
+ * **Module 4: Production Workflows** (Variable Baking & Deployment)
299
+ * **Module 5: CloudFront Functions** (CFF)
242
300
 
243
- ---
301
+ Each exercise comes with a **Business Scenario**, **Starter Template**, and **Full Solution**.
244
302
 
303
+ ---
245
304
 
246
305
  ### License
247
306
 
248
- **CloudFrontize** is licensed under the **[PolyForm Noncommercial 1.0.0](https://www.google.com/search?q=https://polyformproject.org/licenses/noncommercial/1.0.0/)**. For the full legal text and specific terms, please refer to the [LICENSE](https://www.google.com/search?q=./LICENSE) file in this package.
249
-
307
+ **CloudFrontize** is licensed under the **[PolyForm Noncommercial 1.0.0](https://polyformproject.org/licenses/noncommercial/1.0.0/)**. For the full legal text and specific terms, please refer to the [LICENSE](https://polyformproject.org/licenses/noncommercial/1.0.0/) file in this package.
250
308
 
251
309
  * **✅ Free for Individuals & Education:** 100% free for personal projects, open-source contributions, students, and researchers. This includes full access to the **CloudFrontize Academy**.
252
- * **💼 Requires a Commercial License:** Use by for-profit organizations, or for work performed on behalf of a for-profit entity, requires a paid Commercial License.
310
+ * **💼 Requires a Commercial License:** Use by for-profit organizations, or work performed on behalf of a for-profit entity, requires a commercial license.
253
311
  * **⏳ 30-Day Business Trial:** We offer a one-month free evaluation period for professional teams. Integrate CloudFrontize into your workflow, experience the "Zero-Wait" deployment cycle, and measure your team's productivity gains before committing.
254
312
 
255
313
 
@@ -264,7 +322,7 @@ Maintaining high-fidelity AWS emulation takes significant time. If your company
264
322
  **THE SOFTWARE IS PROVIDED "AS IS"**, WITHOUT WARRANTY OF ANY KIND. Testing on CloudFrontize does not guarantee success on live AWS infrastructure. The author is not liable for any production downtime, data loss, or financial damages resulting from the use of this tool. Always validate your logic in an AWS staging environment before a full production rollout.
265
323
 
266
324
  ---
267
- # Donations & Sponsoring
325
+ # Support the Project
268
326
  [<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" name="buy-me-a-coffee" alt="Buy Me A Coffee" width="180">](https://buymeacoffee.com/felipecarrillo100)
269
327
 
270
328
  Creating and maintaining open-source libraries is a passion of mine. If you find this `cloudfrontize` useful and it saves you time, please consider supporting its development. Your contributions help keep the project active and motivated!