vortez 4.1.1 → 5.0.0-dev.14
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/.gitignore +4 -12
- package/README.md +235 -289
- package/build/Template.d.ts +16 -2
- package/build/Template.js +20 -8
- package/build/Template.js.map +1 -1
- package/build/Vortez.d.ts +8 -15
- package/build/Vortez.js +8 -16
- package/build/Vortez.js.map +1 -1
- package/build/beta/Beta.d.ts +8 -0
- package/build/beta/Beta.js +9 -0
- package/build/beta/Beta.js.map +1 -0
- package/build/{Beta → beta}/JwtManager.js +1 -1
- package/build/{Beta → beta}/JwtManager.js.map +1 -1
- package/build/{Beta → beta}/Mail.d.ts +1 -1
- package/build/{Beta → beta}/Mail.js +1 -1
- package/build/beta/Mail.js.map +1 -0
- package/build/logger/Debug.d.ts +174 -0
- package/build/logger/Debug.js +295 -0
- package/build/logger/Debug.js.map +1 -0
- package/build/logger/Logger.d.ts +38 -0
- package/build/logger/Logger.js +48 -0
- package/build/logger/Logger.js.map +1 -0
- package/build/{Server → server}/BodyParser.js.map +1 -1
- package/build/{Server → server}/Cookie.js.map +1 -1
- package/build/server/LoggerManager.d.ts +21 -0
- package/build/server/LoggerManager.js +30 -0
- package/build/server/LoggerManager.js.map +1 -0
- package/build/{Server → server}/Request.d.ts +4 -2
- package/build/{Server → server}/Request.js +2 -1
- package/build/server/Request.js.map +1 -0
- package/build/{Server → server}/Response.d.ts +4 -1
- package/build/{Server → server}/Response.js +24 -8
- package/build/server/Response.js.map +1 -0
- package/build/{Server → server}/Server.d.ts +20 -67
- package/build/server/Server.js +211 -0
- package/build/server/Server.js.map +1 -0
- package/build/server/ServerDebug.d.ts +17 -0
- package/build/server/ServerDebug.js +67 -0
- package/build/server/ServerDebug.js.map +1 -0
- package/build/server/ServerError.d.ts +18 -0
- package/build/server/ServerError.js +15 -0
- package/build/server/ServerError.js.map +1 -0
- package/build/{Server → server}/Session.d.ts +9 -13
- package/build/{Server → server}/Session.js +34 -35
- package/build/server/Session.js.map +1 -0
- package/build/{Config.d.ts → server/config/Config.d.ts} +19 -3
- package/build/server/config/Config.js +60 -0
- package/build/server/config/Config.js.map +1 -0
- package/build/server/config/ConfigLoader.d.ts +24 -0
- package/build/server/config/ConfigLoader.js +53 -0
- package/build/server/config/ConfigLoader.js.map +1 -0
- package/build/server/config/ConfigValidator.d.ts +71 -0
- package/build/server/config/ConfigValidator.js +131 -0
- package/build/server/config/ConfigValidator.js.map +1 -0
- package/build/server/router/HttpRule.d.ts +69 -0
- package/build/server/router/HttpRule.js +96 -0
- package/build/server/router/HttpRule.js.map +1 -0
- package/build/server/router/Router.d.ts +127 -0
- package/build/server/router/Router.js +211 -0
- package/build/server/router/Router.js.map +1 -0
- package/build/server/router/Rule.d.ts +71 -0
- package/build/server/router/Rule.js +113 -0
- package/build/server/router/Rule.js.map +1 -0
- package/build/server/router/WsRule.d.ts +25 -0
- package/build/server/router/WsRule.js +34 -0
- package/build/server/router/WsRule.js.map +1 -0
- package/build/server/router/middleware/HttpMiddleware.d.ts +35 -0
- package/build/server/router/middleware/HttpMiddleware.js +90 -0
- package/build/server/router/middleware/HttpMiddleware.js.map +1 -0
- package/build/server/router/middleware/Middleware.d.ts +77 -0
- package/build/server/router/middleware/Middleware.js +69 -0
- package/build/server/router/middleware/Middleware.js.map +1 -0
- package/build/server/router/middleware/WsMiddleware.d.ts +24 -0
- package/build/server/router/middleware/WsMiddleware.js +90 -0
- package/build/server/router/middleware/WsMiddleware.js.map +1 -0
- package/build/{Server/WebSocket → server/websocket}/Chunk.js.map +1 -1
- package/build/server/websocket/Websocket.d.ts +88 -0
- package/build/{Server/WebSocket/WebSocket.js → server/websocket/Websocket.js} +91 -53
- package/build/server/websocket/Websocket.js.map +1 -0
- package/build/utilities/ConsoleUI.d.ts +88 -0
- package/build/utilities/ConsoleUI.js +141 -0
- package/build/utilities/ConsoleUI.js.map +1 -0
- package/build/utilities/DebugUI.d.ts +66 -0
- package/build/utilities/DebugUI.js +98 -0
- package/build/utilities/DebugUI.js.map +1 -0
- package/build/utilities/Env.d.ts +81 -0
- package/build/{Utilities → utilities}/Env.js +47 -35
- package/build/utilities/Env.js.map +1 -0
- package/build/utilities/Path.d.ts +24 -0
- package/build/utilities/Path.js +36 -0
- package/build/{Utilities → utilities}/Path.js.map +1 -1
- package/build/{Utilities → utilities}/Utilities.d.ts +68 -55
- package/build/{Utilities → utilities}/Utilities.js +36 -19
- package/build/utilities/Utilities.js.map +1 -0
- package/changes.md +122 -88
- package/package.json +10 -13
- package/tests/debug.js +9 -3
- package/tests/test.js +50 -48
- package/tests/utilities.js +1 -1
- package/Notes.md +0 -12
- package/build/Beta/Mail.js.map +0 -1
- package/build/Config.js +0 -33
- package/build/Config.js.map +0 -1
- package/build/ConsoleUI.d.ts +0 -57
- package/build/ConsoleUI.js +0 -110
- package/build/ConsoleUI.js.map +0 -1
- package/build/Debug.d.ts +0 -154
- package/build/Debug.js +0 -256
- package/build/Debug.js.map +0 -1
- package/build/LoggerManager/Logger.d.ts +0 -23
- package/build/LoggerManager/Logger.js +0 -23
- package/build/LoggerManager/Logger.js.map +0 -1
- package/build/LoggerManager/LoggerManager.d.ts +0 -18
- package/build/LoggerManager/LoggerManager.js +0 -30
- package/build/LoggerManager/LoggerManager.js.map +0 -1
- package/build/Server/Request.js.map +0 -1
- package/build/Server/Response.js.map +0 -1
- package/build/Server/Rule.d.ts +0 -81
- package/build/Server/Rule.js +0 -146
- package/build/Server/Rule.js.map +0 -1
- package/build/Server/Server.js +0 -330
- package/build/Server/Server.js.map +0 -1
- package/build/Server/Session.js.map +0 -1
- package/build/Server/WebSocket/WebSocket.d.ts +0 -70
- package/build/Server/WebSocket/WebSocket.js.map +0 -1
- package/build/Utilities/Env.d.ts +0 -75
- package/build/Utilities/Env.js.map +0 -1
- package/build/Utilities/Path.d.ts +0 -18
- package/build/Utilities/Path.js +0 -27
- package/build/Utilities/Utilities.js.map +0 -1
- /package/build/{Beta → beta}/JwtManager.d.ts +0 -0
- /package/build/{Server → server}/BodyParser.d.ts +0 -0
- /package/build/{Server → server}/BodyParser.js +0 -0
- /package/build/{Server → server}/Cookie.d.ts +0 -0
- /package/build/{Server → server}/Cookie.js +0 -0
- /package/build/{Server/WebSocket → server/websocket}/Chunk.d.ts +0 -0
- /package/build/{Server/WebSocket → server/websocket}/Chunk.js +0 -0
package/.gitignore
CHANGED
package/README.md
CHANGED
|
@@ -1,372 +1,318 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 🚀 Vortez
|
|
2
|
+
|
|
3
|
+
This project began as a **personal journey** to deeply understand how web servers work in **Node.js**.
|
|
4
|
+
Throughout its development, I’ve gained **tons of new skills and insights** that I’m excited to share.
|
|
5
|
+
|
|
6
|
+
🛠️ **Continuous Improvement:**
|
|
7
|
+
I constantly refactor the code whenever I spot areas that can be polished or optimized.
|
|
8
|
+
|
|
9
|
+
🌟 **Real-World Usage:**
|
|
10
|
+
I actively use this module in my own web projects, which means I’m always finding new ideas, enhancements, and opportunities to fix bugs based on feedback.
|
|
11
|
+
|
|
12
|
+
💡 **Vision:**
|
|
13
|
+
My goal is to make **Vortez** a tool that helps developers build **APIs**, **PWAs**, **websites**, and—thanks to the [Vizui module](https://github.com/NetFeez/Vizui)—**SPAs** with ease and confidence.
|
|
14
|
+
|
|
15
|
+
Stay tuned for more updates and features! 🚀
|
|
16
|
+
That’s all for now, [NetFeez](https://NetFeez.github.io) out.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
# Installation
|
|
21
|
+
|
|
22
|
+
You can use **npm** to install Vortez:
|
|
23
|
+
|
|
24
|
+
* **Stable version**
|
|
25
|
+
|
|
26
|
+
```console
|
|
27
|
+
mpm install vortez
|
|
28
|
+
```
|
|
29
|
+
* **Development version**
|
|
30
|
+
|
|
31
|
+
```console
|
|
32
|
+
mpm install vortez@dev
|
|
33
|
+
```
|
|
2
34
|
|
|
3
35
|
> [!IMPORTANT]
|
|
4
|
-
>
|
|
5
|
-
>
|
|
6
|
-
> entre las versiones **3.6.5** y **3.7.0**:
|
|
7
|
-
>
|
|
8
|
-
> Se está planteando que las funcionalidades **beta.mail** y **beta.jwt** se muevan a módulos separados.
|
|
9
|
-
> Esta decisión dependerá de qué tan grandes se vuelvan dichas funcionalidades. Por el momento, y para la futura versión **4.0.0**,
|
|
10
|
-
> seguirán estando en el lugar habitual, aunque con ciertos cambios que afectan la compatibilidad con las funciones beta
|
|
11
|
-
> incorporadas en la versión **3.6.5**.
|
|
36
|
+
> You need to set `"type": "module"` in your `package.json` to use **Vortez**.
|
|
37
|
+
> This requirement will be removed in a future version, but for now please configure it like this:
|
|
12
38
|
>
|
|
13
|
-
>
|
|
14
|
-
>
|
|
15
|
-
>
|
|
39
|
+
> ```json
|
|
40
|
+
> {
|
|
41
|
+
> "name": "my-project",
|
|
42
|
+
> "main": "index.js",
|
|
43
|
+
> "type": "module"
|
|
44
|
+
> }
|
|
16
45
|
> ```
|
|
17
|
-
>
|
|
18
|
-
> Como último punto, se planea cambiar el nombre del módulo en npm. Se darán detalles cuando se decida cuál será, y se agregará como dependencia a la última versión de **Vortez** que sea desplegada en npm.
|
|
19
46
|
|
|
47
|
+
---
|
|
20
48
|
|
|
21
|
-
#
|
|
49
|
+
# Documentation
|
|
22
50
|
|
|
23
|
-
|
|
24
|
-
Como comente anteriormente en mi perfil, Vortez permitirá:
|
|
51
|
+
## Static Pages
|
|
25
52
|
|
|
26
|
-
|
|
27
|
-
- [ ] **En proceso** Sistema de plantillas.
|
|
28
|
-
- [x] Gestionar conexiones WebSocket.
|
|
29
|
-
- [ ] Gestionar negociaciones de WebRTC.
|
|
30
|
-
- [ ] Gestionar notificaciones WebPush.
|
|
53
|
+
You can use **Vortez** to serve static pages:
|
|
31
54
|
|
|
32
|
-
|
|
33
|
-
|
|
55
|
+
```js
|
|
56
|
+
// Importing Vortez
|
|
57
|
+
import Vortez from 'vortez';
|
|
34
58
|
|
|
35
|
-
|
|
59
|
+
// Creating the server
|
|
60
|
+
const server = new Vortez();
|
|
36
61
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
publicaré el código de esta manera e iré modificando para corregir esto.
|
|
62
|
+
// Adding rules
|
|
63
|
+
server.router.addFolder('/source', 'source');
|
|
64
|
+
server.router.addFile('/', 'source/index.html');
|
|
41
65
|
|
|
42
|
-
|
|
43
|
-
|
|
66
|
+
// Starting the server
|
|
67
|
+
server.start();
|
|
44
68
|
```
|
|
45
69
|
|
|
46
|
-
|
|
70
|
+
---
|
|
47
71
|
|
|
48
|
-
|
|
49
|
-
- [x] Cambiar los nombres de variables, funciones, clases y descripciones a inglés.
|
|
50
|
-
- [ ] **en proceso** Crear documentación para enseñar a usar el módulo.
|
|
51
|
-
- [ ] **en proceso** Buscar y corregir malas practicas.
|
|
72
|
+
## APIs and Websites
|
|
52
73
|
|
|
53
|
-
|
|
74
|
+
You can use **actions** to execute code and send responses to the client:
|
|
54
75
|
|
|
55
|
-
|
|
76
|
+
```js
|
|
77
|
+
import Vortez from 'vortez';
|
|
56
78
|
|
|
57
|
-
|
|
79
|
+
const server = new Vortez();
|
|
58
80
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
81
|
+
// Action with a static response
|
|
82
|
+
server.router.addAction('GET', '/api/test', (request, response) => {
|
|
83
|
+
response.sendJson({
|
|
84
|
+
message: 'Hello World',
|
|
85
|
+
route: `[${request.method}] -> ${request.url}`
|
|
86
|
+
});
|
|
87
|
+
});
|
|
62
88
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
89
|
+
// Route params and query params
|
|
90
|
+
// Example route param: `/api/params/$id`
|
|
91
|
+
// Example request: `http://localhost/api/params/123`
|
|
92
|
+
server.router.addAction('GET', '/api/params/$id', (request, response) => {
|
|
93
|
+
response.sendJson({
|
|
94
|
+
message: 'Hello World',
|
|
95
|
+
route: `[${request.method}] -> ${request.url}`,
|
|
96
|
+
params: request.ruleParams,
|
|
97
|
+
query: request.searchParams
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// Serving files
|
|
102
|
+
server.router.addAction('GET', '/api/file', (request, response) => {
|
|
103
|
+
response.sendFile('source/index.html');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Sending simple text
|
|
107
|
+
server.router.addAction('GET', '/api/string', (request, response) => {
|
|
108
|
+
response.send('Hello World');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// Starting the server
|
|
112
|
+
server.start();
|
|
70
113
|
```
|
|
71
114
|
|
|
72
|
-
|
|
73
|
-
-->
|
|
74
|
-
- Si en tu package.json tienes la propiedad `"type": "module"`:
|
|
75
|
-
```js
|
|
76
|
-
import Vortez from 'vortez';
|
|
77
|
-
```
|
|
78
|
-
- Si no tienes esta propiedad usa:
|
|
79
|
-
```js
|
|
80
|
-
//Actualmente no esta soportado, en futuras versiones se ampliara su compatibilidad
|
|
81
|
-
```
|
|
115
|
+
---
|
|
82
116
|
|
|
83
|
-
##
|
|
117
|
+
## SPAs
|
|
84
118
|
|
|
85
|
-
|
|
119
|
+
You can serve a single file for multiple URLs, including recursive routes:
|
|
86
120
|
|
|
87
|
-
|
|
88
|
-
|
|
121
|
+
```js
|
|
122
|
+
import Vortez from 'vortez';
|
|
89
123
|
|
|
90
|
-
|
|
124
|
+
const server = new Vortez();
|
|
91
125
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
126
|
+
server.router.addFile('/', 'main.html');
|
|
127
|
+
server.router.addFile('/app/*', 'main.html');
|
|
128
|
+
server.router.addFolder('/public', 'public');
|
|
95
129
|
|
|
96
|
-
|
|
130
|
+
/*
|
|
131
|
+
You can also add other features like actions, files, folders, etc.
|
|
132
|
+
Use addWebSocket for real-time connections.
|
|
133
|
+
*/
|
|
97
134
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
```
|
|
135
|
+
server.start();
|
|
136
|
+
```
|
|
101
137
|
|
|
102
|
-
|
|
138
|
+
---
|
|
103
139
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
> - Actualmente se inicia el servidor HTTP y HTTPS a la vez en este caso
|
|
108
|
-
> esto se corregirá y se pondrá como característica opcional en futuras versiones.
|
|
140
|
+
## Server Configuration
|
|
141
|
+
|
|
142
|
+
You can configure the server using the `server.config` object:
|
|
109
143
|
|
|
110
144
|
```js
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
145
|
+
import Vortez from 'vortez';
|
|
146
|
+
const server = new Vortez();
|
|
147
|
+
|
|
148
|
+
server.config.port = 3000;
|
|
149
|
+
server.config.host = 'localhost';
|
|
150
|
+
server.config.https = {
|
|
151
|
+
key: 'path/to/key.pem',
|
|
152
|
+
cert: 'path/to/cert.pem'
|
|
153
|
+
};
|
|
154
|
+
server.config.templates.error = 'error.html';
|
|
155
|
+
server.config.templates.folder = 'folder.html';
|
|
116
156
|
```
|
|
117
157
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|Tipo |Descripción |
|
|
123
|
-
|----------------------:|:----------------------------------------------------|
|
|
124
|
-
|[Folder](#carpeta) |Comparte una carpeta y sus sub-carpetas |
|
|
125
|
-
|[File](#archivo) |Comparte un único archivo |
|
|
126
|
-
|[Action](#acción) |Te permite trabajar completamente con las solicitudes|
|
|
127
|
-
|[WebSocket](#websocket)|Permite manejar conexiones WebSocket en esa ruta |
|
|
128
|
-
|
|
129
|
-
Los Métodos aceptados actualmente son:
|
|
130
|
-
|
|
131
|
-
|Método|Descripción |
|
|
132
|
-
|-----:|:-------------------------------------------|
|
|
133
|
-
|GET |El método de petición `GET`. |
|
|
134
|
-
|POST |El método de petición `POST`. |
|
|
135
|
-
|PUT |El método de petición `PUT`. |
|
|
136
|
-
|DELETE|El método de petición `DELETE`. |
|
|
137
|
-
|ALL |Todos los métodos anteriormente mencionados.|
|
|
138
|
-
|
|
139
|
-
Como funciona la RuleUrl:<br/>
|
|
140
|
-
|
|
141
|
-
Actualmente la RuleUrl acepta 2 características
|
|
142
|
-
- Comodín * toma todas las sub rutas incluyendo hasta antes de *
|
|
143
|
-
- para /test/* tomaría /test y todo lo demás como /test/algo-mas/x
|
|
144
|
-
- para /test2/*/Algo tomaría /Test2/(cualquier-cosa)/Algo
|
|
145
|
-
es como el comodín $ solo que no guardara en una variable
|
|
146
|
-
- Toma parámetros de la url usando $ seguido del nombre de la variable
|
|
147
|
-
y se puede acceder a ellas desde `Request.RuleParams`
|
|
148
|
-
**Ejemplo**:
|
|
149
|
-
```js
|
|
150
|
-
server.addAction('ALL', '/User/$UserID/Post/$PostID', (request, response) => {
|
|
151
|
-
response.sendJson({
|
|
152
|
-
url: request.url,
|
|
153
|
-
ruleParams: request.ruleParams
|
|
154
|
-
});
|
|
155
|
-
/* Esto devolverá lo siguiente si la ruta fuera /User/111111/Post/222222
|
|
156
|
-
{
|
|
157
|
-
"Url": "/User/111111/Post/222222"
|
|
158
|
-
"RuleParams": {
|
|
159
|
-
"UserID": "111111",
|
|
160
|
-
"PostID": "222222"
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
*/
|
|
164
|
-
});
|
|
165
|
-
```
|
|
166
|
-
**AuthExec**
|
|
167
|
-
Es una función que recibe como parámetro la petición del http
|
|
168
|
-
esta debe retornar un valor booleano, true para decir que la petición esta autenticada y false para decir que no lo esta.
|
|
169
|
-
**Ejemplo**:
|
|
158
|
+
You can also create the server with a configuration object passed to the constructor:
|
|
159
|
+
|
|
160
|
+
* **Using options:**
|
|
161
|
+
|
|
170
162
|
```js
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
163
|
+
const server = new Vortez({
|
|
164
|
+
port: 3000,
|
|
165
|
+
host: 'localhost',
|
|
166
|
+
ssl: null
|
|
174
167
|
});
|
|
175
168
|
```
|
|
176
169
|
|
|
170
|
+
* **Using the Config instance:**
|
|
177
171
|
|
|
178
|
-
|
|
172
|
+
```js
|
|
173
|
+
const config = new Vortez.Config();
|
|
174
|
+
config.port = 3000;
|
|
175
|
+
config.host = 'localhost';
|
|
176
|
+
config.ssl = null;
|
|
179
177
|
|
|
180
|
-
|
|
178
|
+
const server = new Vortez(config);
|
|
179
|
+
```
|
|
181
180
|
|
|
182
|
-
|
|
183
|
-
> - ⚠️No compartas la raíz de tu proyecto, ya que esto daría acceso a **TODO** su contenido.
|
|
184
|
-
> - Datos privados como las llaves privadas de tus certificados.
|
|
185
|
-
> - Contraseñas a bases de datos que estén en los archivos js del lado del servidor.
|
|
186
|
-
> - Tokens de seguridad
|
|
187
|
-
> y en general cualquier otro dato
|
|
188
|
-
> - Esto tomara la ruta que le asignes de forma completa
|
|
189
|
-
> **Ejemplo**: si le asignas la ruta `/src` tomaría todas las sub-rutas como `/src/estilos`
|
|
181
|
+
---
|
|
190
182
|
|
|
191
|
-
|
|
183
|
+
## URL Rules
|
|
192
184
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
185
|
+
URL rules are strings used to define routes handled by the router.
|
|
186
|
+
|
|
187
|
+
The main separator is `/` which indicates a new sub-route:
|
|
188
|
+
|
|
189
|
+
* **`*`**: A wildcard that captures all sub-routes.
|
|
190
|
+
* **`$<name>`**: A dynamic parameter you can access via `request.ruleParams`.
|
|
191
|
+
* **`<string>`**: A literal segment that must match exactly.
|
|
192
|
+
|
|
193
|
+
**Examples**:
|
|
194
|
+
|
|
195
|
+
* `/api/*` — Matches `/api/users`, `/api/posts/comments`, etc.
|
|
196
|
+
* `/user/$id` — Matches `/user/123`, capturing `123` as `id`.
|
|
197
|
+
* `/blog/$category/$postId` — Matches `/blog/tech/42`, capturing `tech` as `category` and `42` as `postId`.
|
|
201
198
|
|
|
199
|
+
---
|
|
202
200
|
|
|
203
|
-
|
|
204
|
-
// De esta manera tienes mayor control sobre la creación de la regla.
|
|
205
|
-
server.addRules(
|
|
206
|
-
/*
|
|
207
|
-
este constructor acepta 5 parámetros para crearse correctamente:
|
|
208
|
-
Tipo, Método, UrlRule, Content, AuthExec.
|
|
209
|
-
AuthExec es opcional.
|
|
210
|
-
*/
|
|
211
|
-
new Vortez.Rule('Folder', 'GET', '/MyFolder/', 'Test/', () => true),
|
|
212
|
-
);
|
|
201
|
+
## Rules
|
|
213
202
|
|
|
203
|
+
In **Vortez**, there are four types of routers:
|
|
204
|
+
|
|
205
|
+
| Type | Description |
|
|
206
|
+
| ----------------------- | ------------------------------------------------------ |
|
|
207
|
+
| [Folder](#folder) | Serves a folder and its sub-folders |
|
|
208
|
+
| [File](#file) | Serves a single file |
|
|
209
|
+
| [Action](#action) | Lets you handle requests programmatically |
|
|
210
|
+
| [WebSocket](#websocket) | Allows managing WebSocket connections on a given route |
|
|
211
|
+
|
|
212
|
+
### Folder
|
|
213
|
+
|
|
214
|
+
Serves a folder and its sub-folders:
|
|
215
|
+
|
|
216
|
+
> [!WARNING]
|
|
217
|
+
> Do not share the root of your project, as this would expose **ALL** its contents:
|
|
218
|
+
>
|
|
219
|
+
> * Private certificate keys
|
|
220
|
+
> * Database passwords in server-side `.js` files
|
|
221
|
+
> * Security tokens
|
|
222
|
+
> * And any other sensitive data
|
|
223
|
+
>
|
|
224
|
+
> Also:
|
|
225
|
+
>
|
|
226
|
+
> * The entire assigned path will be exposed.
|
|
227
|
+
>
|
|
228
|
+
> * **Example:** assigning `/src` would include all sub-routes like `/src/styles`.
|
|
229
|
+
|
|
230
|
+
```js
|
|
231
|
+
server.router.addFolder('/my-folder', 'path/to/folder');
|
|
232
|
+
server.router.addFolder('/my-folder-2', '/path/to/folder/absolute');
|
|
214
233
|
```
|
|
215
234
|
|
|
216
|
-
###
|
|
235
|
+
### File
|
|
217
236
|
|
|
218
|
-
|
|
237
|
+
Serves a single file:
|
|
219
238
|
|
|
220
239
|
```js
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
Esta función acepta 3 parámetros:
|
|
224
|
-
UrlRule, Source, AuthExec.
|
|
225
|
-
AuthExec es opcional.
|
|
226
|
-
*/
|
|
227
|
-
server.addFile('/MyFile', 'changes.md');
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
// Usando el constructor de la clase Rule:
|
|
231
|
-
// De esta manera tienes mayor control sobre la creación de la regla.
|
|
232
|
-
server.addRules(
|
|
233
|
-
/*
|
|
234
|
-
este constructor acepta 5 parámetros para crearse correctamente:
|
|
235
|
-
Tipo, Método, UrlRule, Content, AuthExec.
|
|
236
|
-
AuthExec es opcional.
|
|
237
|
-
*/
|
|
238
|
-
new Vortez.Rule('File', 'GET', '/MyFile/*', 'changes.md', () => true),
|
|
239
|
-
);
|
|
240
|
+
server.router.addFile('/my-file', 'path/to/file');
|
|
241
|
+
server.router.addFile('/my-file-2', '/path/to/file/absolute');
|
|
240
242
|
```
|
|
241
243
|
|
|
242
|
-
###
|
|
244
|
+
### Action
|
|
243
245
|
|
|
244
|
-
|
|
246
|
+
Lets you handle requests programmatically:
|
|
245
247
|
|
|
246
248
|
```js
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
server.addAction('GET', '/', (request, response) => {
|
|
254
|
-
if (request.cookies.has('User_ID')) {
|
|
255
|
-
response.send("El User_ID que estas usando es:" + request.cookies.get('User_ID'));
|
|
256
|
-
} else {
|
|
257
|
-
response.sendFile('./ErrorUsuario.html');
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
// Usando el constructor de la clase Rule:
|
|
264
|
-
// En este caso no hay diferencia a usar AddAction e incluso deberás especificar el tipo.
|
|
265
|
-
Server.AddRules(
|
|
266
|
-
/*
|
|
267
|
-
este constructor acepta 5 parámetros para crearse correctamente:
|
|
268
|
-
Tipo, Método, UrlRule, Content, AuthExec.
|
|
269
|
-
AuthExec es opcional.
|
|
270
|
-
*/
|
|
271
|
-
new Vortez.Rule('Action', 'GET', '/', (request, response) => {
|
|
272
|
-
if (request.cookies.has('User_ID')) {
|
|
273
|
-
response.send("El User_ID que estas usando es:" + request.cookies.get('User_ID'));
|
|
274
|
-
} else {
|
|
275
|
-
response.sendFile('./ErrorUsuario.html');
|
|
276
|
-
}
|
|
277
|
-
})
|
|
278
|
-
);
|
|
249
|
+
server.router.addAction('GET', '/my-action', (request, response) => {
|
|
250
|
+
response.sendJson({
|
|
251
|
+
message: 'Hello World',
|
|
252
|
+
route: `[${request.method}] -> ${request.url}`
|
|
253
|
+
});
|
|
254
|
+
});
|
|
279
255
|
```
|
|
280
256
|
|
|
281
257
|
### WebSocket
|
|
282
258
|
|
|
283
|
-
|
|
284
|
-
> [!NOTE]
|
|
285
|
-
> Las url de los web sockets van por medio distinto al de las peticiones de File, Folder y Action por ende
|
|
286
|
-
> no tendrán conflictos si son similares o iguales a ellas
|
|
259
|
+
Allows managing WebSocket connections on a given route:
|
|
287
260
|
|
|
261
|
+
> [!NOTE]
|
|
262
|
+
> WebSocket URLs use a separate namespace from Files, Folders, and Actions,
|
|
263
|
+
> so they won’t conflict even if they share the same route patterns.
|
|
288
264
|
|
|
289
265
|
```js
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
Esta función acepta 3 parámetros:
|
|
293
|
-
UrlRule, Action, AuthExec.
|
|
294
|
-
AuthExec es opcional.
|
|
295
|
-
*/
|
|
296
|
-
const Conexiones = new Set();
|
|
266
|
+
const connections = new Set();
|
|
267
|
+
|
|
297
268
|
server.addWebSocket('/Test/WS-Chat', (request, socket) => {
|
|
298
|
-
console.log('[WS]
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
socket.on('
|
|
269
|
+
console.log('[WS] New connection');
|
|
270
|
+
connections.forEach(user => user.Send('A user has connected.'));
|
|
271
|
+
connections.add(socket);
|
|
272
|
+
|
|
273
|
+
socket.on('finish', () => connections.delete(socket));
|
|
274
|
+
socket.on('error', error => console.log('[WS-Error]:', error));
|
|
275
|
+
|
|
303
276
|
socket.on('message', (data, info) => {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
if (Usuario !== socket) Usuario.Send(data.toString());
|
|
277
|
+
if (info.opCode === 1) {
|
|
278
|
+
console.log('[WS] Message:', data.toString());
|
|
279
|
+
connections.forEach(user => {
|
|
280
|
+
if (user !== socket) user.Send(data.toString());
|
|
309
281
|
});
|
|
310
|
-
} else if (info.opCode
|
|
311
|
-
|
|
282
|
+
} else if (info.opCode === 8) {
|
|
283
|
+
connections.forEach(user => user.Send('A user has disconnected.'));
|
|
312
284
|
}
|
|
313
285
|
});
|
|
314
286
|
});
|
|
287
|
+
```
|
|
315
288
|
|
|
289
|
+
---
|
|
316
290
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
Server.AddRules(
|
|
321
|
-
/*
|
|
322
|
-
este constructor acepta 5 parámetros para crearse correctamente:
|
|
323
|
-
Tipo, Método, UrlRule, Content, AuthExec.
|
|
324
|
-
AuthExec es opcional.
|
|
325
|
-
A pesar de recibir el método este no se tomara en cuenta para las conexiones web socket.
|
|
326
|
-
*/
|
|
327
|
-
new Vortez.Rule('WebSocket', 'GET', '/Test/WS-Chat', (request, socket) => {
|
|
328
|
-
console.log('[WS] CM: Conexión nueva')
|
|
329
|
-
Conexiones.forEach((Usuario) => Usuario.Send("Un usuario se conecto"));
|
|
330
|
-
Conexiones.add(socket);
|
|
331
|
-
socket.on('finish', () => Conexiones.delete(socket));
|
|
332
|
-
socket.on('error', (error) => console.log('[WS-Error]:', error));
|
|
333
|
-
socket.on('message', (data, info) => {
|
|
334
|
-
//console.log(Info.OPCode);
|
|
335
|
-
if (info.opCode == 1) {
|
|
336
|
-
console.log('[WS] MSS:', data.toString());
|
|
337
|
-
Conexiones.forEach((Usuario) => {
|
|
338
|
-
if (Usuario !== socket) Usuario.Send(data.toString());
|
|
339
|
-
});
|
|
340
|
-
} else if (info.opCode == 8) {
|
|
341
|
-
Conexiones.forEach((Usuario) => Usuario.Send("Un usuario se desconecto"));
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
})
|
|
345
|
-
);
|
|
346
|
-
```
|
|
291
|
+
# Development Version
|
|
292
|
+
|
|
293
|
+
## Currently in Development
|
|
347
294
|
|
|
348
|
-
|
|
295
|
+
The following features are under active development:
|
|
349
296
|
|
|
350
|
-
|
|
297
|
+
* **\[JsonWT]**: JSON Web Token (JWT) support.
|
|
298
|
+
* **\[Mail]**: Email sending functionality.
|
|
299
|
+
* **\[Server]**: Dynamic authentication system for routing.
|
|
351
300
|
|
|
352
|
-
|
|
353
|
-
- [JsonWT]: El uso de Json Web Tokens.
|
|
354
|
-
- [Mail]: El envió de E-Mails.
|
|
355
|
-
- [Server]: El sistema de autenticación dinámico para las reglas de enrutamiento.
|
|
301
|
+
## Installation
|
|
356
302
|
|
|
357
|
-
|
|
303
|
+
To install the development version:
|
|
358
304
|
|
|
359
|
-
Para instalar la version en desarrollo:
|
|
360
305
|
```console
|
|
361
306
|
mpm install vortez@dev
|
|
362
307
|
```
|
|
308
|
+
|
|
363
309
|
> [!WARNING]
|
|
364
|
-
>
|
|
365
|
-
>
|
|
310
|
+
> This version may contain bugs.
|
|
311
|
+
> It includes the latest features that may not yet be fully tested.
|
|
312
|
+
|
|
313
|
+
To access development features not yet listed in `changes.md`:
|
|
366
314
|
|
|
367
|
-
Para acceder a las funciones en desarrollo sin añadir mencionadas en changes.md
|
|
368
315
|
```js
|
|
369
|
-
import { Beta } from 'vortez'
|
|
370
|
-
const Mail = Beta
|
|
371
|
-
|
|
372
|
-
```
|
|
316
|
+
import { Beta } from 'vortez';
|
|
317
|
+
const { Mail, JwtManager } = Beta;
|
|
318
|
+
```
|
package/build/Template.d.ts
CHANGED
|
@@ -4,10 +4,15 @@
|
|
|
4
4
|
* @license Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
export declare class Template {
|
|
7
|
-
/** Regular expressions used
|
|
7
|
+
/** Regular expressions used for parsing and processing the template. */
|
|
8
8
|
private static expressions;
|
|
9
9
|
/**
|
|
10
10
|
* Load and compile a template.
|
|
11
|
+
* This method reads a template file from the specified path,
|
|
12
|
+
* checks if it's a valid file, and then compiles its content
|
|
13
|
+
* using the provided data object.
|
|
14
|
+
*
|
|
15
|
+
* @example `Template.load('./templates/myTemplate.html', { username: 'John Doe' });`
|
|
11
16
|
* @param path - The path to the template file.
|
|
12
17
|
* @param data - The data used to compile the template.
|
|
13
18
|
* @returns The compiled template.
|
|
@@ -17,7 +22,12 @@ export declare class Template {
|
|
|
17
22
|
static load(path: string, data: Template.dataObject): Promise<string>;
|
|
18
23
|
/**
|
|
19
24
|
* Compile a template.
|
|
20
|
-
*
|
|
25
|
+
* This internal method takes the raw template content and the data object
|
|
26
|
+
* and performs the actual compilation, replacing variables and processing
|
|
27
|
+
* object/array blocks according to the defined syntax.
|
|
28
|
+
*
|
|
29
|
+
* @example `Template.compile('Hello, ${name}!', { name: 'Alice' });`
|
|
30
|
+
* @param content - The content of the template.
|
|
21
31
|
* @param data - The data used to compile the template.
|
|
22
32
|
* @returns The compiled template.
|
|
23
33
|
* @throws Error if key and value names are equal in object blocks.
|
|
@@ -25,6 +35,10 @@ export declare class Template {
|
|
|
25
35
|
private static compile;
|
|
26
36
|
}
|
|
27
37
|
export declare namespace Template {
|
|
38
|
+
/**
|
|
39
|
+
* Represents the structure of the data object used for template compilation.
|
|
40
|
+
* It is a key-value store where keys are strings and values can be of any type.
|
|
41
|
+
*/
|
|
28
42
|
interface dataObject {
|
|
29
43
|
[key: string]: any;
|
|
30
44
|
}
|