kaelum 1.0.0 → 1.1.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.
- package/README.md +21 -1
- package/cli/index.js +1 -1
- package/cli/templates/web/app.js +7 -8
- package/cli/templates/web/package.json +1 -3
- package/core/setConfig.js +30 -0
- package/createApp.js +2 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Kaelum
|
|
2
2
|
|
|
3
|
-
**Kaelum** is a minimalist Node.js framework designed to simplify the creation of web pages and REST APIs, especially for beginners. Inspired by Python's clean syntax and powered by Express.js, Kaelum automates project setup and server configuration with an intuitive CLI.
|
|
3
|
+
**Kaelum** is a minimalist Node.js framework designed to simplify the creation of web pages and REST APIs, especially for beginners and students. Inspired by Python's clean syntax and powered by Express.js, Kaelum automates project setup and server configuration with an intuitive CLI.
|
|
4
4
|
|
|
5
5
|
## 📦 Installation
|
|
6
6
|
|
|
@@ -10,6 +10,13 @@ You can create a new project with Kaelum using:
|
|
|
10
10
|
npx kaelum create
|
|
11
11
|
````
|
|
12
12
|
|
|
13
|
+
This command initializes a Kaelum project with a pre-configured structure based on the MVC model, including:
|
|
14
|
+
|
|
15
|
+
* Static file serving
|
|
16
|
+
* Template-ready HTML/CSS homepage
|
|
17
|
+
* Built-in route system
|
|
18
|
+
* Public folder and initial structure
|
|
19
|
+
|
|
13
20
|
Then install dependencies and start your app:
|
|
14
21
|
|
|
15
22
|
```bash
|
|
@@ -81,6 +88,19 @@ Globally apply middleware to all routes.
|
|
|
81
88
|
setMiddleware(require('helmet')());
|
|
82
89
|
```
|
|
83
90
|
|
|
91
|
+
### ⚙️ `setConfig(options)`
|
|
92
|
+
|
|
93
|
+
You can enable common configurations using `setConfig`:
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
app.setConfig({
|
|
97
|
+
cors: true,
|
|
98
|
+
helmet: true,
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Internally, Kaelum will automatically load and apply `cors` and `helmet` if enabled.
|
|
103
|
+
|
|
84
104
|
### 🚀 `start(port)`
|
|
85
105
|
|
|
86
106
|
Start the server.
|
package/cli/index.js
CHANGED
package/cli/templates/web/app.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
const kaelum = require(
|
|
2
|
-
const cors = require('cors');
|
|
3
|
-
const helmet = require('helmet');
|
|
4
|
-
|
|
1
|
+
const kaelum = require("kaelum");
|
|
5
2
|
const app = kaelum();
|
|
6
3
|
|
|
7
|
-
//
|
|
8
|
-
app.
|
|
9
|
-
|
|
4
|
+
// SetConfig para aplicar configurações de segurança e middlewares
|
|
5
|
+
app.setConfig({
|
|
6
|
+
cors: true,
|
|
7
|
+
helmet: true,
|
|
8
|
+
});
|
|
10
9
|
|
|
11
10
|
// Importa e registra as rotas
|
|
12
|
-
const routes = require(
|
|
11
|
+
const routes = require("./routes");
|
|
13
12
|
routes(app);
|
|
14
13
|
|
|
15
14
|
// Inicia o servidor
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const cors = require("cors");
|
|
2
|
+
const helmet = require("helmet");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Aplica configurações de segurança e middlewares automáticos.
|
|
6
|
+
* @param {Object} app - A instância do Express.
|
|
7
|
+
* @param {Object} options - Opções de configuração.
|
|
8
|
+
* @param {boolean} options.cors - Ativa o CORS se true.
|
|
9
|
+
* @param {boolean} options.helmet - Ativa o Helmet se true.
|
|
10
|
+
*/
|
|
11
|
+
function setConfig(app, options = {}) {
|
|
12
|
+
if (options.cors) {
|
|
13
|
+
const corsOpts = options.cors === true ? {} : options.cors;
|
|
14
|
+
app.use(cors(corsOpts));
|
|
15
|
+
console.log("🛡️ CORS ativado.");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (options.helmet) {
|
|
19
|
+
const helmetOpts = options.helmet === true ? {} : options.helmet;
|
|
20
|
+
app.use(helmet(helmetOpts));
|
|
21
|
+
console.log("🛡️ Helmet ativado.");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Futuras configurações:
|
|
25
|
+
// - options.static
|
|
26
|
+
// - options.logs
|
|
27
|
+
// - options.port
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = setConfig;
|
package/createApp.js
CHANGED
|
@@ -2,6 +2,7 @@ const express = require('express');
|
|
|
2
2
|
const start = require('./core/start');
|
|
3
3
|
const addRoute = require('./core/addRoute');
|
|
4
4
|
const setMiddleware = require('./core/setMiddleware');
|
|
5
|
+
const setConfig = require('./core/setConfig');
|
|
5
6
|
|
|
6
7
|
function createApp() {
|
|
7
8
|
const app = express();
|
|
@@ -14,6 +15,7 @@ function createApp() {
|
|
|
14
15
|
app.start = (port, callback) => start(app, port, callback);
|
|
15
16
|
app.addRoute = (path, handlers) => addRoute(app, path, handlers);
|
|
16
17
|
app.setMiddleware = (middleware) => setMiddleware(app, middleware);
|
|
18
|
+
app.setConfig = (config) => setConfig(app, config);
|
|
17
19
|
|
|
18
20
|
return app;
|
|
19
21
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kaelum",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A minimalist Node.js framework for building web pages and APIs with simplicity and speed.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"exports": {
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"author": "Matheus Campagnolo",
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"express": "^4.18.2",
|
|
30
|
-
"helmet": "^7.0.0",
|
|
31
29
|
"cors": "^2.8.5",
|
|
30
|
+
"express": "^4.18.2",
|
|
32
31
|
"fs-extra": "^11.3.0",
|
|
32
|
+
"helmet": "^7.2.0",
|
|
33
33
|
"inquirer": "^12.6.0"
|
|
34
34
|
}
|
|
35
|
-
}
|
|
35
|
+
}
|