kaelum 1.8.2 → 1.8.3
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
CHANGED
|
@@ -84,11 +84,14 @@ app.start();
|
|
|
84
84
|
## ⚡ Quick Start
|
|
85
85
|
|
|
86
86
|
```bash
|
|
87
|
-
# Scaffold a new project
|
|
88
|
-
npx kaelum create my-app
|
|
87
|
+
# Scaffold a new project (interactive — picks language + template)
|
|
88
|
+
npx kaelum create my-app
|
|
89
89
|
|
|
90
|
-
# Or
|
|
91
|
-
npx kaelum create my-
|
|
90
|
+
# Or non-interactive with a specific template
|
|
91
|
+
npx kaelum create my-app --template js-web
|
|
92
|
+
npx kaelum create my-api --template js-api
|
|
93
|
+
npx kaelum create my-app --template ts-web
|
|
94
|
+
npx kaelum create my-api --template ts-api
|
|
92
95
|
|
|
93
96
|
# Run it
|
|
94
97
|
cd my-app && npm install && npm start
|
|
@@ -96,21 +99,35 @@ cd my-app && npm install && npm start
|
|
|
96
99
|
|
|
97
100
|
> No global install needed — `npx` handles everything.
|
|
98
101
|
|
|
102
|
+
### Available Templates
|
|
103
|
+
|
|
104
|
+
| Template | Language | Description |
|
|
105
|
+
| -------- | ---------- | ----------------------------------------- |
|
|
106
|
+
| `js-web` | JavaScript | MVC with views & static files |
|
|
107
|
+
| `js-api` | JavaScript | REST API ready |
|
|
108
|
+
| `ts-web` | TypeScript | MVC with views & static files (tsx + tsc) |
|
|
109
|
+
| `ts-api` | TypeScript | REST API ready (tsx + tsc) |
|
|
110
|
+
|
|
111
|
+
> Legacy aliases `web` and `api` map to `js-web` and `js-api`.
|
|
112
|
+
|
|
99
113
|
---
|
|
100
114
|
|
|
101
115
|
## ✨ Features
|
|
102
116
|
|
|
103
|
-
| Feature
|
|
104
|
-
|
|
105
|
-
| 🚀 **Zero-Config Start**
|
|
106
|
-
| 🌳 **Tree Routing**
|
|
107
|
-
| 🔒 **Security Built-in**
|
|
108
|
-
| 🛠️ **CLI Scaffolding**
|
|
109
|
-
| 📦 **Dual Module**
|
|
110
|
-
| 🏥 **Health Checks**
|
|
111
|
-
| ⚡ **Middleware Manager** | Track, add, and remove middleware programmatically
|
|
112
|
-
| 🔄 **Redirects**
|
|
113
|
-
| 🛡️ **Error Handler**
|
|
117
|
+
| Feature | Description |
|
|
118
|
+
| ------------------------ | -------------------------------------------------------------- |
|
|
119
|
+
| 🚀 **Zero-Config Start** | JSON parsing, static files, EJS views — all pre-configured |
|
|
120
|
+
| 🌳 **Tree Routing** | Recursive nested routes with `addRoute` and `apiRoute` |
|
|
121
|
+
| 🔒 **Security Built-in** | One-toggle CORS, Helmet, and XSS protection |
|
|
122
|
+
| 🛠️ **CLI Scaffolding** | `npx kaelum create` with JS and TS templates (web + API) |
|
|
123
|
+
| 📦 **Dual Module** | Works with both `require()` and `import` |
|
|
124
|
+
| 🏥 **Health Checks** | Built-in `/health` endpoint with readiness probes |
|
|
125
|
+
| ⚡ **Middleware Manager** | Track, add, and remove middleware programmatically |
|
|
126
|
+
| 🔄 **Redirects** | Declarative redirect maps with single, array, or object syntax |
|
|
127
|
+
| 🛡️ **Error Handler** | Standardized JSON/HTML error responses with hooks |
|
|
128
|
+
| ⏱️ **Rate Limiting** | Built-in zero-dependency in-memory rate limiter |
|
|
129
|
+
| 🧩 **Plugin System** | Register and manage plugins with dedup guard |
|
|
130
|
+
| 🔌 **Graceful Shutdown** | Signal handling, connection draining, and cleanup hooks |
|
|
114
131
|
|
|
115
132
|
---
|
|
116
133
|
|
|
@@ -145,6 +162,8 @@ app.setConfig({
|
|
|
145
162
|
bodyParser: true, // JSON + urlencoded (default: on)
|
|
146
163
|
port: 3000, // preferred port
|
|
147
164
|
views: { engine: "ejs", path: "./views" },
|
|
165
|
+
rateLimit: true, // enable rate limiting (default: 100 req/15 min)
|
|
166
|
+
gracefulShutdown: { timeout: 10000 }, // signal handling + cleanup
|
|
148
167
|
});
|
|
149
168
|
```
|
|
150
169
|
|
|
@@ -185,20 +204,32 @@ app.apiRoute("products", {
|
|
|
185
204
|
app.start(3000); // start server
|
|
186
205
|
app.setMiddleware("/admin", authMiddleware); // scoped middleware
|
|
187
206
|
app.redirect("/old", "/new", 301); // redirects
|
|
188
|
-
app.healthCheck("/health");
|
|
189
|
-
app.useErrorHandler({ exposeStack: false });
|
|
207
|
+
app.healthCheck("/health"); // health endpoint
|
|
208
|
+
app.useErrorHandler({ exposeStack: false }); // error handling
|
|
209
|
+
app.plugin(myPlugin, { key: "value" }); // register plugin
|
|
210
|
+
app.onShutdown(() => cleanup()); // shutdown hook
|
|
211
|
+
app.close(); // graceful close
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### CLI Commands
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
kaelum create # interactive project scaffolding
|
|
218
|
+
kaelum --version # show installed version
|
|
219
|
+
kaelum info # show environment details
|
|
220
|
+
kaelum help # show all commands
|
|
190
221
|
```
|
|
191
222
|
|
|
192
223
|
---
|
|
193
224
|
|
|
194
225
|
## 📁 Project Templates
|
|
195
226
|
|
|
196
|
-
### Web
|
|
227
|
+
### JavaScript Web (`js-web`)
|
|
197
228
|
|
|
198
229
|
```
|
|
199
230
|
my-web-app/
|
|
200
231
|
├── public/ # Static assets
|
|
201
|
-
├── views/ #
|
|
232
|
+
├── views/ # HTML templates
|
|
202
233
|
├── controllers/ # Route logic (MVC)
|
|
203
234
|
├── middlewares/ # Custom middleware
|
|
204
235
|
├── routes.js # Route definitions
|
|
@@ -206,7 +237,7 @@ my-web-app/
|
|
|
206
237
|
└── package.json
|
|
207
238
|
```
|
|
208
239
|
|
|
209
|
-
### API
|
|
240
|
+
### JavaScript API (`js-api`)
|
|
210
241
|
|
|
211
242
|
```
|
|
212
243
|
my-api/
|
|
@@ -217,6 +248,34 @@ my-api/
|
|
|
217
248
|
└── package.json
|
|
218
249
|
```
|
|
219
250
|
|
|
251
|
+
### TypeScript Web (`ts-web`)
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
my-web-app/
|
|
255
|
+
├── public/ # Static assets
|
|
256
|
+
├── views/ # HTML templates
|
|
257
|
+
├── src/
|
|
258
|
+
│ ├── controllers/ # Route logic (MVC)
|
|
259
|
+
│ ├── middlewares/ # Custom middleware
|
|
260
|
+
│ ├── routes.ts # Route definitions
|
|
261
|
+
│ └── app.ts # Entry point
|
|
262
|
+
├── tsconfig.json
|
|
263
|
+
└── package.json
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### TypeScript API (`ts-api`)
|
|
267
|
+
|
|
268
|
+
```
|
|
269
|
+
my-api/
|
|
270
|
+
├── src/
|
|
271
|
+
│ ├── controllers/ # Business logic
|
|
272
|
+
│ ├── middlewares/ # Auth, validation
|
|
273
|
+
│ ├── routes.ts # API routes
|
|
274
|
+
│ └── app.ts # Entry point
|
|
275
|
+
├── tsconfig.json
|
|
276
|
+
└── package.json
|
|
277
|
+
```
|
|
278
|
+
|
|
220
279
|
---
|
|
221
280
|
|
|
222
281
|
## 🧪 Testing
|
|
@@ -239,10 +298,10 @@ See also: [Code of Conduct](https://github.com/kaelumjs/.github/blob/main/CODE_O
|
|
|
239
298
|
|
|
240
299
|
## 🌐 Ecosystem
|
|
241
300
|
|
|
242
|
-
| Package
|
|
243
|
-
|
|
244
|
-
| [kaelum](https://www.npmjs.com/package/kaelum)
|
|
245
|
-
| [kaelumjs/docs](https://github.com/kaelumjs/docs)
|
|
301
|
+
| Package | Description |
|
|
302
|
+
| ------------------------------------------------------- | -------------------------- |
|
|
303
|
+
| [kaelum](https://www.npmjs.com/package/kaelum) | Core framework |
|
|
304
|
+
| [kaelumjs/docs](https://github.com/kaelumjs/docs) | Documentation site |
|
|
246
305
|
| [kaelumjs/.github](https://github.com/kaelumjs/.github) | Shared community standards |
|
|
247
306
|
|
|
248
307
|
---
|
|
@@ -1,49 +1,52 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
6
|
-
<title>Kaelum — Hello</title>
|
|
7
|
-
<link rel="stylesheet" href="/style.css" />
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<main class="container">
|
|
11
|
-
<header>
|
|
12
|
-
<h1>Kaelum.js</h1>
|
|
13
|
-
<p class="subtitle">
|
|
14
|
-
Minimalist framework for Web Apps & APIs — Demo Template
|
|
15
|
-
</p>
|
|
16
|
-
</header>
|
|
17
3
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
7
|
+
<title>Kaelum — Hello</title>
|
|
8
|
+
<link rel="stylesheet" href="/style.css" />
|
|
9
|
+
</head>
|
|
24
10
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
11
|
+
<body>
|
|
12
|
+
<main class="container">
|
|
13
|
+
<header>
|
|
14
|
+
<h1>Kaelum.js</h1>
|
|
15
|
+
<p class="subtitle">
|
|
16
|
+
Minimalist framework for Web Apps & APIs — Demo Template
|
|
17
|
+
</p>
|
|
18
|
+
</header>
|
|
19
|
+
|
|
20
|
+
<section class="content">
|
|
21
|
+
<h2>Welcome 👋</h2>
|
|
22
|
+
<p>
|
|
23
|
+
This template was automatically generated by the
|
|
24
|
+
<strong>Kaelum</strong> CLI.
|
|
25
|
+
</p>
|
|
26
|
+
|
|
27
|
+
<div class="cards">
|
|
28
|
+
<div class="card">
|
|
29
|
+
<h3>Routes</h3>
|
|
30
|
+
<p>
|
|
31
|
+
Available routes: <code>/</code>, <code>/about</code>, <code>/about/team</code>,
|
|
32
|
+
<code>/dashboard</code>, <code>/dashboard/settings</code>.
|
|
33
|
+
</p>
|
|
34
|
+
</div>
|
|
35
|
+
<div class="card">
|
|
36
|
+
<h3>Security</h3>
|
|
37
|
+
<p>CORS and Helmet are enabled via <code>app.setConfig</code>.</p>
|
|
41
38
|
</div>
|
|
39
|
+
<div class="card">
|
|
40
|
+
<h3>Health Check</h3>
|
|
41
|
+
<p>Built-in health endpoint at <code>/health</code>.</p>
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
<p class="small">
|
|
46
|
+
Generated by Kaelum CLI
|
|
47
|
+
</p>
|
|
48
|
+
</section>
|
|
49
|
+
</main>
|
|
50
|
+
</body>
|
|
42
51
|
|
|
43
|
-
|
|
44
|
-
Generated by Kaelum CLI • Kaelum v1.8.0
|
|
45
|
-
</p>
|
|
46
|
-
</section>
|
|
47
|
-
</main>
|
|
48
|
-
</body>
|
|
49
|
-
</html>
|
|
52
|
+
</html>
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// controllers/pagesController.ts
|
|
2
2
|
const path = require("path");
|
|
3
3
|
|
|
4
|
+
// Uses process.cwd() so it resolves from the project root in both
|
|
5
|
+
// development (tsx) and production (compiled dist/), since views/
|
|
6
|
+
// lives at the project root alongside src/.
|
|
4
7
|
const view = (file: string): string => path.join(process.cwd(), "views", file);
|
|
5
8
|
|
|
6
9
|
const home = (req: any, res: any): void => {
|
|
@@ -1,49 +1,52 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
6
|
-
<title>Kaelum — Hello</title>
|
|
7
|
-
<link rel="stylesheet" href="/style.css" />
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<main class="container">
|
|
11
|
-
<header>
|
|
12
|
-
<h1>Kaelum.js</h1>
|
|
13
|
-
<p class="subtitle">
|
|
14
|
-
Minimalist framework for Web Apps & APIs — TypeScript Template
|
|
15
|
-
</p>
|
|
16
|
-
</header>
|
|
17
3
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
7
|
+
<title>Kaelum — Hello</title>
|
|
8
|
+
<link rel="stylesheet" href="/style.css" />
|
|
9
|
+
</head>
|
|
24
10
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
11
|
+
<body>
|
|
12
|
+
<main class="container">
|
|
13
|
+
<header>
|
|
14
|
+
<h1>Kaelum.js</h1>
|
|
15
|
+
<p class="subtitle">
|
|
16
|
+
Minimalist framework for Web Apps & APIs — TypeScript Template
|
|
17
|
+
</p>
|
|
18
|
+
</header>
|
|
19
|
+
|
|
20
|
+
<section class="content">
|
|
21
|
+
<h2>Welcome 👋</h2>
|
|
22
|
+
<p>
|
|
23
|
+
This TypeScript template was automatically generated by the
|
|
24
|
+
<strong>Kaelum</strong> CLI.
|
|
25
|
+
</p>
|
|
26
|
+
|
|
27
|
+
<div class="cards">
|
|
28
|
+
<div class="card">
|
|
29
|
+
<h3>Routes</h3>
|
|
30
|
+
<p>
|
|
31
|
+
Available routes: <code>/</code>, <code>/about</code>, <code>/about/team</code>,
|
|
32
|
+
<code>/dashboard</code>, <code>/dashboard/settings</code>.
|
|
33
|
+
</p>
|
|
34
|
+
</div>
|
|
35
|
+
<div class="card">
|
|
36
|
+
<h3>TypeScript</h3>
|
|
37
|
+
<p>Run <code>npm run dev</code> for hot-reload via <code>tsx</code>.</p>
|
|
41
38
|
</div>
|
|
39
|
+
<div class="card">
|
|
40
|
+
<h3>Health Check</h3>
|
|
41
|
+
<p>Built-in health endpoint at <code>/health</code>.</p>
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
<p class="small">
|
|
46
|
+
Generated by Kaelum CLI
|
|
47
|
+
</p>
|
|
48
|
+
</section>
|
|
49
|
+
</main>
|
|
50
|
+
</body>
|
|
42
51
|
|
|
43
|
-
|
|
44
|
-
Generated by Kaelum CLI • Kaelum v1.8.0
|
|
45
|
-
</p>
|
|
46
|
-
</section>
|
|
47
|
-
</main>
|
|
48
|
-
</body>
|
|
49
|
-
</html>
|
|
52
|
+
</html>
|