vortez 4.1.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/.gitignore +13 -0
- package/LICENSE +201 -0
- package/Notes.md +12 -0
- package/README.md +372 -0
- package/build/Beta/JwtManager.d.ts +114 -0
- package/build/Beta/JwtManager.js +249 -0
- package/build/Beta/JwtManager.js.map +1 -0
- package/build/Beta/Mail.d.ts +60 -0
- package/build/Beta/Mail.js +192 -0
- package/build/Beta/Mail.js.map +1 -0
- package/build/Config.d.ts +39 -0
- package/build/Config.js +33 -0
- package/build/Config.js.map +1 -0
- package/build/ConsoleUI.d.ts +57 -0
- package/build/ConsoleUI.js +110 -0
- package/build/ConsoleUI.js.map +1 -0
- package/build/Debug.d.ts +154 -0
- package/build/Debug.js +256 -0
- package/build/Debug.js.map +1 -0
- package/build/LoggerManager/Logger.d.ts +23 -0
- package/build/LoggerManager/Logger.js +23 -0
- package/build/LoggerManager/Logger.js.map +1 -0
- package/build/LoggerManager/LoggerManager.d.ts +18 -0
- package/build/LoggerManager/LoggerManager.js +30 -0
- package/build/LoggerManager/LoggerManager.js.map +1 -0
- package/build/Server/BodyParser.d.ts +125 -0
- package/build/Server/BodyParser.js +162 -0
- package/build/Server/BodyParser.js.map +1 -0
- package/build/Server/Cookie.d.ts +72 -0
- package/build/Server/Cookie.js +102 -0
- package/build/Server/Cookie.js.map +1 -0
- package/build/Server/Request.d.ts +61 -0
- package/build/Server/Request.js +79 -0
- package/build/Server/Request.js.map +1 -0
- package/build/Server/Response.d.ts +90 -0
- package/build/Server/Response.js +241 -0
- package/build/Server/Response.js.map +1 -0
- package/build/Server/Rule.d.ts +81 -0
- package/build/Server/Rule.js +146 -0
- package/build/Server/Rule.js.map +1 -0
- package/build/Server/Server.d.ts +157 -0
- package/build/Server/Server.js +330 -0
- package/build/Server/Server.js.map +1 -0
- package/build/Server/Session.d.ts +66 -0
- package/build/Server/Session.js +97 -0
- package/build/Server/Session.js.map +1 -0
- package/build/Server/WebSocket/Chunk.d.ts +36 -0
- package/build/Server/WebSocket/Chunk.js +81 -0
- package/build/Server/WebSocket/Chunk.js.map +1 -0
- package/build/Server/WebSocket/WebSocket.d.ts +70 -0
- package/build/Server/WebSocket/WebSocket.js +184 -0
- package/build/Server/WebSocket/WebSocket.js.map +1 -0
- package/build/Template.d.ts +32 -0
- package/build/Template.js +69 -0
- package/build/Template.js.map +1 -0
- package/build/Utilities/Env.d.ts +75 -0
- package/build/Utilities/Env.js +123 -0
- package/build/Utilities/Env.js.map +1 -0
- package/build/Utilities/Path.d.ts +18 -0
- package/build/Utilities/Path.js +27 -0
- package/build/Utilities/Path.js.map +1 -0
- package/build/Utilities/Utilities.d.ts +147 -0
- package/build/Utilities/Utilities.js +110 -0
- package/build/Utilities/Utilities.js.map +1 -0
- package/build/Vortez.d.ts +20 -0
- package/build/Vortez.js +22 -0
- package/build/Vortez.js.map +1 -0
- package/changes.md +89 -0
- package/examples/in-docs.js +96 -0
- package/global/Source/Logo_960.png +0 -0
- package/global/Source/Logo_SM_960.png +0 -0
- package/global/Style/Template/Error.css +30 -0
- package/global/Style/Template/Folder.css +77 -0
- package/global/Style/Template/Template.css +128 -0
- package/global/Template/Error.vhtml +29 -0
- package/global/Template/Folder.vhtml +41 -0
- package/package.json +47 -0
- package/tests/Template/template.js +18 -0
- package/tests/Template/template.txt +13 -0
- package/tests/Template/template.vhtml +23 -0
- package/tests/debug.js +28 -0
- package/tests/jwtManager/jwtManager.js +110 -0
- package/tests/test.js +129 -0
- package/tests/test.vhtml +14 -0
- package/tests/utilities.js +28 -0
- package/tests/websocket.vhtml +86 -0
package/.gitignore
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2023 - 2026 NetFeez
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/Notes.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
[Server]
|
|
2
|
+
- Separar la lógica de enrutamiento en funciones mas pequeñas
|
|
3
|
+
- Crear funciones para las comprobaciones de los condicionales
|
|
4
|
+
ternarios para mejorar la legibilidad
|
|
5
|
+
- Reconsiderar el uso de Session para que sea opcional para el usuario
|
|
6
|
+
- Poner el uso del Debug.Log como opcional al usuario para evitar la
|
|
7
|
+
creación de demasiados archivos o eliminar logs viejos
|
|
8
|
+
- Eliminar comentarios en el futuro: [Server/Server.js] LN(249)
|
|
9
|
+
- Añadir comprobaciones para AddFile, AddFolder, AddAction, AddWebSocket: [Server/Server.js]
|
|
10
|
+
|
|
11
|
+
[Bugs]
|
|
12
|
+
- Al usar WSL para levantar el servidor en una carpeta de windows no cargan las carpetas por que no encuentra la plantilla Folder.vhtml.
|
package/README.md
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
# Importante
|
|
2
|
+
|
|
3
|
+
> [!IMPORTANT]
|
|
4
|
+
> La futura versión **3.7.0** será omitida hasta la versión **4.0.0**.
|
|
5
|
+
> La razón de esta decisión fue que hubo cambios que afectan la compatibilidad
|
|
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**.
|
|
12
|
+
>
|
|
13
|
+
> Recuerda que puedes acceder a la versión de desarrollo descargando la rama **dev** del repositorio o por medio de npm:
|
|
14
|
+
> ```bash
|
|
15
|
+
> npm i vortez@dev
|
|
16
|
+
> ```
|
|
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
|
+
|
|
20
|
+
|
|
21
|
+
# Vortez
|
|
22
|
+
|
|
23
|
+
Hola! soy [NetFeez](https://NetFeez.github.io).<br/>
|
|
24
|
+
Como comente anteriormente en mi perfil, Vortez permitirá:
|
|
25
|
+
|
|
26
|
+
- [x] Crear servidores HTTP y HTTPS.
|
|
27
|
+
- [ ] **En proceso** Sistema de plantillas.
|
|
28
|
+
- [x] Gestionar conexiones WebSocket.
|
|
29
|
+
- [ ] Gestionar negociaciones de WebRTC.
|
|
30
|
+
- [ ] Gestionar notificaciones WebPush.
|
|
31
|
+
|
|
32
|
+
Es posible que algunos de los puntos anteriores se subdividan en proyectos diferentes<br/>
|
|
33
|
+
o que se cree un gestor de paquetes para implementar las funcionalidades dentro del mismo<br/>
|
|
34
|
+
|
|
35
|
+
## Sobre el proyecto
|
|
36
|
+
|
|
37
|
+
Actualmente tengo en local una copia del proyecto con varias de las funcionalidades<br/>
|
|
38
|
+
este comenzó como un proyecto personal y con fines de práctica de pensamiento lógico<br/>
|
|
39
|
+
por lo tanto no tiene las mejores prácticas ni la mejor documentación, sin embargo<br/>
|
|
40
|
+
publicaré el código de esta manera e iré modificando para corregir esto.
|
|
41
|
+
|
|
42
|
+
```console
|
|
43
|
+
mpm install vortez
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Futuras correcciones**
|
|
47
|
+
|
|
48
|
+
- [x] Documentar clases y funciones para intellisense.
|
|
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.
|
|
52
|
+
|
|
53
|
+
Esto es todo por el momento, [NetFeez](https://NetFeez.github.io) se retira.
|
|
54
|
+
|
|
55
|
+
# Documentación
|
|
56
|
+
|
|
57
|
+
Primero debemos instalar el modulo usando
|
|
58
|
+
|
|
59
|
+
```console
|
|
60
|
+
mpm install vortez
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
También es necesario que en tu package.json este el proyecto como type: module
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"name": "my-project",
|
|
67
|
+
"main": "index.js",
|
|
68
|
+
"type": "module"
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Una ves tengas Vortez en tu proyecto y lo hayas configurado como modulo debes importarlo<br/>
|
|
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
|
+
```
|
|
82
|
+
|
|
83
|
+
## Servidor HTTP
|
|
84
|
+
|
|
85
|
+
Para crear un servidor HTTP puedes hacerlo de diferentes maneras:
|
|
86
|
+
|
|
87
|
+
> [!NOTE]
|
|
88
|
+
> Debes haber importado el modulo primero.
|
|
89
|
+
|
|
90
|
+
- Solo pasando el puerto
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
const Server = new Vortez(80);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
- Pasando Puerto y Host
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
const Server = new Vortez(80, 'MiDominio.com');
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Servidor HTTPS
|
|
103
|
+
|
|
104
|
+
> [!NOTE]
|
|
105
|
+
> - Debes tener un certificado ssl (la clave publica y privada).
|
|
106
|
+
> - Si no quieres especificar un host usa `null`.
|
|
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.
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
const server = new Vortez(80, null, {
|
|
112
|
+
pubKey: 'Cert/MiDominio.pem', //El archivo con la clave publica (Obligatorio)
|
|
113
|
+
privKey: 'Cert/MiDominio.key', //El archivo con la clave privada (Obligatorio)
|
|
114
|
+
port: 443 //El puerto donde se abrirá el servidor (Opcional)
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Agregar enrutador
|
|
119
|
+
|
|
120
|
+
En **`Vortez`** existen 4 clases de enrutador:
|
|
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**:
|
|
170
|
+
```js
|
|
171
|
+
// si la petición se hace con el QueryParam Auth y es igual a AuthYes se confirmara la autenticidad de la petición
|
|
172
|
+
server.addFile('/FileWA', 'changes.md', (Request) => {
|
|
173
|
+
return Request.queryParams.has('Auth') && Request.queryParams.get('Auth') == 'AuthYes'
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
### Carpeta
|
|
179
|
+
|
|
180
|
+
Comparte una carpeta y todo su contenido tanto archivos como sub-carpetas
|
|
181
|
+
|
|
182
|
+
> [!WARNING]
|
|
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`
|
|
190
|
+
|
|
191
|
+
Para añadir este tipo de regla usa:
|
|
192
|
+
|
|
193
|
+
```js
|
|
194
|
+
// Usando AddFile
|
|
195
|
+
/*
|
|
196
|
+
Esta función acepta 3 parámetros:
|
|
197
|
+
UrlRule, Source, AuthExec.
|
|
198
|
+
AuthExec es opcional.
|
|
199
|
+
*/
|
|
200
|
+
server.addFolder('/MyFolder', 'Test');
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
// Usando el constructor de la clase Rule:
|
|
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
|
+
);
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Archivo
|
|
217
|
+
|
|
218
|
+
Comparte un archivo especifico
|
|
219
|
+
|
|
220
|
+
```js
|
|
221
|
+
// Usando AddFolder
|
|
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
|
+
```
|
|
241
|
+
|
|
242
|
+
### Acción
|
|
243
|
+
|
|
244
|
+
Te permite tener total control sobre esas peticiones:
|
|
245
|
+
|
|
246
|
+
```js
|
|
247
|
+
// Usando AddAction
|
|
248
|
+
/*
|
|
249
|
+
Esta función acepta 4 parámetros:
|
|
250
|
+
Método, UrlRule, Action, AuthExec.
|
|
251
|
+
AuthExec es opcional.
|
|
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
|
+
);
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### WebSocket
|
|
282
|
+
|
|
283
|
+
Esto te permite gestionar una conexión WebSocket completa:
|
|
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
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
```js
|
|
290
|
+
// Usando AddWebSocket
|
|
291
|
+
/*
|
|
292
|
+
Esta función acepta 3 parámetros:
|
|
293
|
+
UrlRule, Action, AuthExec.
|
|
294
|
+
AuthExec es opcional.
|
|
295
|
+
*/
|
|
296
|
+
const Conexiones = new Set();
|
|
297
|
+
server.addWebSocket('/Test/WS-Chat', (request, socket) => {
|
|
298
|
+
console.log('[WS] CM: Conexión nueva')
|
|
299
|
+
Conexiones.forEach((Usuario) => Usuario.Send("Un usuario se conecto"));
|
|
300
|
+
Conexiones.add(socket);
|
|
301
|
+
socket.on('finish', () => Conexiones.delete(socket));
|
|
302
|
+
socket.on('error', (error) => console.log('[WS-Error]:', error));
|
|
303
|
+
socket.on('message', (data, info) => {
|
|
304
|
+
//console.log(Info.OPCode);
|
|
305
|
+
if (info.opCode == 1) {
|
|
306
|
+
console.log('[WS] MSS:', data.toString());
|
|
307
|
+
Conexiones.forEach((Usuario) => {
|
|
308
|
+
if (Usuario !== socket) Usuario.Send(data.toString());
|
|
309
|
+
});
|
|
310
|
+
} else if (info.opCode == 8) {
|
|
311
|
+
Conexiones.forEach((Usuario) => Usuario.Send("Un usuario se desconecto"));
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
// Usando el constructor de la clase Rule:
|
|
318
|
+
// En este caso no hay diferencia a usar AddWebSocket e incluso deberás especificar el tipo y el método.
|
|
319
|
+
const Conexiones = new Set();
|
|
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
|
+
```
|
|
347
|
+
|
|
348
|
+
# Version Dev
|
|
349
|
+
|
|
350
|
+
## En desarrollo
|
|
351
|
+
|
|
352
|
+
En el momento están en desarrollo:
|
|
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.
|
|
356
|
+
|
|
357
|
+
## Instalación
|
|
358
|
+
|
|
359
|
+
Para instalar la version en desarrollo:
|
|
360
|
+
```console
|
|
361
|
+
mpm install vortez@dev
|
|
362
|
+
```
|
|
363
|
+
> [!WARNING]
|
|
364
|
+
> - Esta version podría contener errores.
|
|
365
|
+
> - Contiene la version mas reciente del proyecto.
|
|
366
|
+
|
|
367
|
+
Para acceder a las funciones en desarrollo sin añadir mencionadas en changes.md
|
|
368
|
+
```js
|
|
369
|
+
import { Beta } from 'vortez'
|
|
370
|
+
const Mail = Beta.Mail;
|
|
371
|
+
const JsonWT = Beta.JsonWT;
|
|
372
|
+
```
|