jerkjs 2.1.1 → 2.1.2
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/CHANGELOG.md +3 -2
- package/README.md +1 -1
- package/examples.arj +0 -0
- package/index.js +1 -1
- package/lib/middleware/compressor.js +34 -18
- package/package.json +1 -1
- package/standard/CompressionTestController.js +38 -0
- package/standard/HealthController.js +16 -0
- package/standard/HomeController.js +12 -0
- package/standard/ProductController.js +18 -0
- package/standard/README.md +47 -0
- package/standard/UserController.js +23 -0
- package/standard/package.json +22 -0
- package/standard/routes.json +58 -0
- package/standard/server.js +140 -0
- package/cookies.txt +0 -5
- package/examples/advanced/controllers/productController.js +0 -64
- package/examples/advanced/controllers/userController.js +0 -85
- package/examples/advanced/routes.json +0 -51
- package/examples/advanced_example.js +0 -93
- package/examples/basic/controllers/userController.js +0 -85
- package/examples/basic_example.js +0 -72
- package/examples/frontend/README.md +0 -71
- package/examples/frontend/app.js +0 -71
- package/examples/frontend/controllers/apiController.js +0 -39
- package/examples/frontend/controllers/authController.js +0 -220
- package/examples/frontend/controllers/formController.js +0 -47
- package/examples/frontend/controllers/messageController.js +0 -96
- package/examples/frontend/controllers/pageController.js +0 -178
- package/examples/frontend/controllers/staticController.js +0 -167
- package/examples/frontend/routes.json +0 -90
- package/examples/hooks/app.js +0 -136
- package/examples/hooks/controllers/authController.js +0 -54
- package/examples/hooks/controllers/mainController.js +0 -41
- package/examples/hooks/controllers/productController.js +0 -39
- package/examples/hooks/controllers/userController.js +0 -69
- package/examples/hooks/routes.json +0 -51
- package/examples/hooks/views/home.html +0 -50
- package/examples/mvc_example/app.js +0 -138
- package/examples/mvc_example/views/home/index.html +0 -26
- package/examples/mvc_example/views/home/simple.html +0 -3
- package/examples/mvc_example/views/layout.html +0 -23
- package/examples/mvc_example/views/test.html +0 -3
- package/examples/mvc_example/views/user/invalid.html +0 -6
- package/examples/mvc_example/views/user/list.html +0 -36
- package/examples/mvc_example/views/user/notfound.html +0 -6
- package/examples/mvc_example/views/user/profile.html +0 -11
- package/examples/mvc_routes_example/app.js +0 -34
- package/examples/mvc_routes_example/controllers/mainController.js +0 -27
- package/examples/mvc_routes_example/controllers/productController.js +0 -47
- package/examples/mvc_routes_example/controllers/userController.js +0 -76
- package/examples/mvc_routes_example/routes.json +0 -30
- package/examples/mvc_routes_example/views/layout.html +0 -31
- package/examples/mvc_routes_example/views/main/index.html +0 -11
- package/examples/mvc_routes_example/views/product/catalog.html +0 -24
- package/examples/mvc_routes_example/views/user/invalid.html +0 -6
- package/examples/mvc_routes_example/views/user/list.html +0 -40
- package/examples/mvc_routes_example/views/user/notfound.html +0 -6
- package/examples/mvc_routes_example/views/user/profile.html +0 -18
- package/examples/mvc_welcome/README.md +0 -34
- package/examples/mvc_welcome/app.js +0 -50
- package/examples/mvc_welcome/controllers/welcomeController.js +0 -41
- package/examples/mvc_welcome/package.json +0 -26
- package/examples/mvc_welcome/views/home/welcome.html +0 -82
- package/examples/performance_demo/app.js +0 -172
- package/examples/performance_demo_with_hooks/README.md +0 -52
- package/examples/performance_demo_with_hooks/app.js +0 -290
- package/examples/public/README.md +0 -92
- package/examples/public/app.js +0 -72
- package/examples/public/controllers/healthController.js +0 -20
- package/examples/public/controllers/mainController.js +0 -22
- package/examples/public/controllers/userController.js +0 -139
- package/examples/public/routes.json +0 -51
- package/examples/v2/README.md +0 -72
- package/examples/v2/app.js +0 -74
- package/examples/v2/app_fixed.js +0 -74
- package/examples/v2/controllers/authController.js +0 -64
- package/examples/v2/controllers/mainController.js +0 -24
- package/examples/v2/controllers/protectedController.js +0 -12
- package/examples/v2/controllers/userController.js +0 -16
- package/examples/v2/package.json +0 -27
- package/examples/v2/routes.json +0 -30
- package/examples/v2/test_api.sh +0 -47
- package/examples/v2/tokens_example.sqlite +0 -0
- package/examples/v2.1_firewall_demo/README.md +0 -113
- package/examples/v2.1_firewall_demo/app.js +0 -182
- package/examples/v2.1_firewall_demo/package.json +0 -27
- package/examples/v2.1_hooks_demo/README.md +0 -85
- package/examples/v2.1_hooks_demo/app.js +0 -101
- package/examples/v2.1_hooks_demo/controllers/hooksController.js +0 -29
- package/examples/v2.1_hooks_demo/controllers/mainController.js +0 -18
- package/examples/v2.1_hooks_demo/package.json +0 -27
- package/examples/v2.1_hooks_demo/routes.json +0 -16
- package/examples/v2.1_openapi_demo/README.md +0 -82
- package/examples/v2.1_openapi_demo/app.js +0 -296
- package/examples/v2.1_openapi_demo/package.json +0 -26
- package/examples/v2_cors/README.md +0 -82
- package/examples/v2_cors/app.js +0 -108
- package/examples/v2_cors/package.json +0 -23
- package/examples/v2_json_auth/README.md +0 -83
- package/examples/v2_json_auth/app.js +0 -72
- package/examples/v2_json_auth/controllers/authController.js +0 -67
- package/examples/v2_json_auth/controllers/mainController.js +0 -16
- package/examples/v2_json_auth/controllers/protectedController.js +0 -12
- package/examples/v2_json_auth/controllers/tokenController.js +0 -28
- package/examples/v2_json_auth/controllers/userController.js +0 -15
- package/examples/v2_json_auth/package.json +0 -26
- package/examples/v2_json_auth/routes.json +0 -37
- package/examples/v2_json_auth/tokens.json +0 -20
- package/examples/v2_mariadb_auth/README.md +0 -94
- package/examples/v2_mariadb_auth/app.js +0 -81
- package/examples/v2_mariadb_auth/controllers/authController.js +0 -95
- package/examples/v2_mariadb_auth/controllers/mainController.js +0 -31
- package/examples/v2_mariadb_auth/controllers/protectedController.js +0 -12
- package/examples/v2_mariadb_auth/controllers/userController.js +0 -17
- package/examples/v2_mariadb_auth/package.json +0 -27
- package/examples/v2_mariadb_auth/routes.json +0 -37
- package/examples/v2_no_auth/README.md +0 -75
- package/examples/v2_no_auth/app.js +0 -72
- package/examples/v2_no_auth/controllers/healthController.js +0 -14
- package/examples/v2_no_auth/controllers/mainController.js +0 -19
- package/examples/v2_no_auth/controllers/productController.js +0 -31
- package/examples/v2_no_auth/controllers/publicController.js +0 -16
- package/examples/v2_no_auth/package.json +0 -22
- package/examples/v2_no_auth/routes.json +0 -37
- package/examples/v2_oauth/README.md +0 -70
- package/examples/v2_oauth/app.js +0 -90
- package/examples/v2_oauth/controllers/mainController.js +0 -45
- package/examples/v2_oauth/controllers/oauthController.js +0 -247
- package/examples/v2_oauth/controllers/protectedController.js +0 -13
- package/examples/v2_oauth/controllers/userController.js +0 -17
- package/examples/v2_oauth/package.json +0 -26
- package/examples/v2_oauth/routes.json +0 -44
- package/examples/v2_openapi/README.md +0 -77
- package/examples/v2_openapi/app.js +0 -222
- package/examples/v2_openapi/controllers/authController.js +0 -52
- package/examples/v2_openapi/controllers/mainController.js +0 -26
- package/examples/v2_openapi/controllers/productController.js +0 -17
- package/examples/v2_openapi/controllers/userController.js +0 -27
- package/examples/v2_openapi/package.json +0 -26
- package/examples/v2_openapi/routes.json +0 -37
- package/v2examplle/v2_json_auth/README.md +0 -83
- package/v2examplle/v2_json_auth/app.js +0 -72
- package/v2examplle/v2_json_auth/controllers/authController.js +0 -67
- package/v2examplle/v2_json_auth/controllers/mainController.js +0 -16
- package/v2examplle/v2_json_auth/controllers/protectedController.js +0 -12
- package/v2examplle/v2_json_auth/controllers/tokenController.js +0 -28
- package/v2examplle/v2_json_auth/controllers/userController.js +0 -15
- package/v2examplle/v2_json_auth/package.json +0 -26
- package/v2examplle/v2_json_auth/routes.json +0 -37
- package/v2examplle/v2_json_auth/tokens.json +0 -20
- package/v2examplle/v2_mariadb_auth/README.md +0 -94
- package/v2examplle/v2_mariadb_auth/app.js +0 -81
- package/v2examplle/v2_mariadb_auth/controllers/authController.js +0 -95
- package/v2examplle/v2_mariadb_auth/controllers/mainController.js +0 -31
- package/v2examplle/v2_mariadb_auth/controllers/protectedController.js +0 -12
- package/v2examplle/v2_mariadb_auth/controllers/userController.js +0 -17
- package/v2examplle/v2_mariadb_auth/package.json +0 -27
- package/v2examplle/v2_mariadb_auth/routes.json +0 -37
- package/v2examplle/v2_sqlite_auth/README.md +0 -72
- package/v2examplle/v2_sqlite_auth/app.js +0 -74
- package/v2examplle/v2_sqlite_auth/app_fixed.js +0 -74
- package/v2examplle/v2_sqlite_auth/controllers/authController.js +0 -64
- package/v2examplle/v2_sqlite_auth/controllers/mainController.js +0 -24
- package/v2examplle/v2_sqlite_auth/controllers/protectedController.js +0 -12
- package/v2examplle/v2_sqlite_auth/controllers/userController.js +0 -16
- package/v2examplle/v2_sqlite_auth/package.json +0 -27
- package/v2examplle/v2_sqlite_auth/routes.json +0 -30
- package/v2examplle/v2_sqlite_auth/test_api.sh +0 -47
- package/v2examplle/v2_sqlite_auth/tokens_example.sqlite +0 -0
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ejemplo de uso del sistema MVC para el framework JERK
|
|
3
|
-
* Demostración de vistas y controladores MVC
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const { APIServer, Router, ControllerBase } = require('../../index');
|
|
7
|
-
|
|
8
|
-
// Crear un controlador personalizado que extienda ControllerBase
|
|
9
|
-
class HomeController extends ControllerBase {
|
|
10
|
-
constructor(options = {}) {
|
|
11
|
-
super(options);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// Acción para mostrar la página de inicio
|
|
15
|
-
index(req, res) {
|
|
16
|
-
// Establecer variables para la vista
|
|
17
|
-
this.set('title', 'Página de Inicio');
|
|
18
|
-
this.set('message', '¡Bienvenido al framework JERK!');
|
|
19
|
-
this.set('users', [
|
|
20
|
-
{ name: 'Juan', email: 'juan@example.com' },
|
|
21
|
-
{ name: 'María', email: 'maria@example.com' },
|
|
22
|
-
{ name: 'Pedro', email: 'pedro@example.com' }
|
|
23
|
-
]);
|
|
24
|
-
|
|
25
|
-
// Renderizar la vista
|
|
26
|
-
this.render(res, 'home/index', {
|
|
27
|
-
currentTime: new Date().toISOString()
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Acción para mostrar el perfil de un usuario
|
|
32
|
-
profile(req, res) {
|
|
33
|
-
// Obtener el ID del usuario de los parámetros
|
|
34
|
-
const userIdParam = this.input('id', '1');
|
|
35
|
-
|
|
36
|
-
// Validar que el ID sea un número entero positivo (no solo que empiece con un número)
|
|
37
|
-
if (!/^\d+$/.test(userIdParam) || parseInt(userIdParam) <= 0) {
|
|
38
|
-
// Si no es un ID válido, mostrar error
|
|
39
|
-
this.set('title', 'ID de usuario inválido');
|
|
40
|
-
this.render(res, 'user/invalid', {
|
|
41
|
-
userId: userIdParam
|
|
42
|
-
});
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const userId = parseInt(userIdParam);
|
|
47
|
-
|
|
48
|
-
// Array real de usuarios
|
|
49
|
-
const users = [
|
|
50
|
-
{ id: 1, name: 'Ana García', email: 'ana@example.com', registered: '2026-01-01T10:00:00Z', active: true },
|
|
51
|
-
{ id: 2, name: 'Carlos López', email: 'carlos@example.com', registered: '2026-01-02T11:30:00Z', active: false },
|
|
52
|
-
{ id: 3, name: 'Laura Martínez', email: 'laura@example.com', registered: '2026-01-03T14:20:00Z', active: true },
|
|
53
|
-
{ id: 4, name: 'Pedro Rodríguez', email: 'pedro@example.com', registered: '2026-01-04T09:15:00Z', active: true },
|
|
54
|
-
{ id: 5, name: 'María Sánchez', email: 'maria@example.com', registered: '2026-01-05T16:45:00Z', active: false }
|
|
55
|
-
];
|
|
56
|
-
|
|
57
|
-
// Buscar el usuario por ID
|
|
58
|
-
const user = users.find(u => u.id === userId);
|
|
59
|
-
|
|
60
|
-
if (!user) {
|
|
61
|
-
// Si no se encuentra el usuario, mostrar error
|
|
62
|
-
this.set('title', 'Usuario no encontrado');
|
|
63
|
-
this.render(res, 'user/notfound', {
|
|
64
|
-
userId: userId
|
|
65
|
-
});
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Establecer variables para la vista
|
|
70
|
-
this.set('title', `Perfil de ${user.name}`);
|
|
71
|
-
this.set('user', user);
|
|
72
|
-
|
|
73
|
-
// Renderizar la vista de perfil
|
|
74
|
-
this.render(res, 'user/profile');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Acción para mostrar la lista de usuarios
|
|
78
|
-
users(req, res) {
|
|
79
|
-
// Array real de usuarios (el mismo que en profile para consistencia)
|
|
80
|
-
const users = [
|
|
81
|
-
{ id: 1, name: 'Ana García', email: 'ana@example.com', registered: '2026-01-01T10:00:00Z', active: true },
|
|
82
|
-
{ id: 2, name: 'Carlos López', email: 'carlos@example.com', registered: '2026-01-02T11:30:00Z', active: false },
|
|
83
|
-
{ id: 3, name: 'Laura Martínez', email: 'laura@example.com', registered: '2026-01-03T14:20:00Z', active: true },
|
|
84
|
-
{ id: 4, name: 'Pedro Rodríguez', email: 'pedro@example.com', registered: '2026-01-04T09:15:00Z', active: true },
|
|
85
|
-
{ id: 5, name: 'María Sánchez', email: 'maria@example.com', registered: '2026-01-05T16:45:00Z', active: false }
|
|
86
|
-
];
|
|
87
|
-
|
|
88
|
-
// Establecer variables para la vista
|
|
89
|
-
this.set('title', 'Lista de Usuarios');
|
|
90
|
-
this.set('users', users);
|
|
91
|
-
|
|
92
|
-
// Renderizar la vista de usuarios
|
|
93
|
-
this.render(res, 'user/list');
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Crear instancia del servidor
|
|
98
|
-
const server = new APIServer({
|
|
99
|
-
port: 9000,
|
|
100
|
-
host: 'localhost'
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// Crear instancia del router
|
|
104
|
-
const router = new Router();
|
|
105
|
-
|
|
106
|
-
// Crear instancia del controlador
|
|
107
|
-
const homeController = new HomeController({ viewsPath: './examples/mvc_example/views' });
|
|
108
|
-
|
|
109
|
-
// Definir rutas
|
|
110
|
-
router
|
|
111
|
-
.get('/', (req, res) => {
|
|
112
|
-
// Establecer la solicitud y respuesta en el controlador
|
|
113
|
-
homeController.setRequestResponse(req, res);
|
|
114
|
-
homeController.index(req, res);
|
|
115
|
-
})
|
|
116
|
-
.get('/profile', (req, res) => {
|
|
117
|
-
homeController.setRequestResponse(req, res);
|
|
118
|
-
homeController.profile(req, res);
|
|
119
|
-
})
|
|
120
|
-
.get('/users', (req, res) => {
|
|
121
|
-
homeController.setRequestResponse(req, res);
|
|
122
|
-
homeController.users(req, res);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
// Agregar las rutas del router al servidor
|
|
126
|
-
const routes = router.getRoutes();
|
|
127
|
-
for (const route of routes) {
|
|
128
|
-
server.addRoute(route.method, route.path, route.handler);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Iniciar el servidor
|
|
132
|
-
server.start(() => {
|
|
133
|
-
console.log('Servidor MVC iniciado en http://localhost:9000');
|
|
134
|
-
console.log('Rutas disponibles:');
|
|
135
|
-
console.log('- http://localhost:9000/ (Página de inicio)');
|
|
136
|
-
console.log('- http://localhost:9000/profile?id=1 (Perfil de usuario)');
|
|
137
|
-
console.log('- http://localhost:9000/users (Lista de usuarios)');
|
|
138
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
<h1>{{title}}</h1>
|
|
2
|
-
<p>{{message}}</p>
|
|
3
|
-
|
|
4
|
-
<h2>Usuarios Registrados</h2>
|
|
5
|
-
{{if users}}
|
|
6
|
-
<table>
|
|
7
|
-
<thead>
|
|
8
|
-
<tr>
|
|
9
|
-
<th>Nombre</th>
|
|
10
|
-
<th>Email</th>
|
|
11
|
-
</tr>
|
|
12
|
-
</thead>
|
|
13
|
-
<tbody>
|
|
14
|
-
{{foreach:users}}
|
|
15
|
-
<tr>
|
|
16
|
-
<td>{{item.name}}</td>
|
|
17
|
-
<td>{{item.email}}</td>
|
|
18
|
-
</tr>
|
|
19
|
-
{{endforeach}}
|
|
20
|
-
</tbody>
|
|
21
|
-
</table>
|
|
22
|
-
{{else}}
|
|
23
|
-
<p>No hay usuarios registrados.</p>
|
|
24
|
-
{{endif}}
|
|
25
|
-
|
|
26
|
-
<p>Hora actual: {{currentTime}}</p>
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="es">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>{{title}}</title>
|
|
7
|
-
<style>
|
|
8
|
-
body { font-family: Arial, sans-serif; margin: 40px; background-color: #f5f5f5; }
|
|
9
|
-
.container { max-width: 800px; margin: 0 auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
|
|
10
|
-
h1 { color: #333; }
|
|
11
|
-
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
|
|
12
|
-
th, td { padding: 10px; text-align: left; border-bottom: 1px solid #ddd; }
|
|
13
|
-
th { background-color: #f2f2f2; }
|
|
14
|
-
.active { color: green; }
|
|
15
|
-
.inactive { color: red; }
|
|
16
|
-
</style>
|
|
17
|
-
</head>
|
|
18
|
-
<body>
|
|
19
|
-
<div class="container">
|
|
20
|
-
{{content}}
|
|
21
|
-
</div>
|
|
22
|
-
</body>
|
|
23
|
-
</html>
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
<h1>{{title}}</h1>
|
|
2
|
-
|
|
3
|
-
{{if users}}
|
|
4
|
-
<table>
|
|
5
|
-
<thead>
|
|
6
|
-
<tr>
|
|
7
|
-
<th>ID</th>
|
|
8
|
-
<th>Nombre</th>
|
|
9
|
-
<th>Email</th>
|
|
10
|
-
<th>Estado</th>
|
|
11
|
-
<th>Acciones</th>
|
|
12
|
-
</tr>
|
|
13
|
-
</thead>
|
|
14
|
-
<tbody>
|
|
15
|
-
{{foreach:users}}
|
|
16
|
-
<tr>
|
|
17
|
-
<td>{{item.id}}</td>
|
|
18
|
-
<td>{{item.name}}</td>
|
|
19
|
-
<td>{{item.email}}</td>
|
|
20
|
-
<td>
|
|
21
|
-
{{if item.active}}
|
|
22
|
-
<span class="active">Activo</span>
|
|
23
|
-
{{else}}
|
|
24
|
-
<span class="inactive">Inactivo</span>
|
|
25
|
-
{{endif}}
|
|
26
|
-
</td>
|
|
27
|
-
<td><a href="/profile?id={{item.id}}">Ver Perfil</a></td>
|
|
28
|
-
</tr>
|
|
29
|
-
{{endforeach}}
|
|
30
|
-
</tbody>
|
|
31
|
-
</table>
|
|
32
|
-
{{else}}
|
|
33
|
-
<p>No hay usuarios registrados.</p>
|
|
34
|
-
{{endif}}
|
|
35
|
-
|
|
36
|
-
<a href="/">Volver a la página de inicio</a>
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
<h1>{{title}}</h1>
|
|
2
|
-
|
|
3
|
-
<div>
|
|
4
|
-
<h2>Información del Usuario</h2>
|
|
5
|
-
<p><strong>ID:</strong> {{user.id}}</p>
|
|
6
|
-
<p><strong>Nombre:</strong> {{user.name}}</p>
|
|
7
|
-
<p><strong>Email:</strong> {{user.email}}</p>
|
|
8
|
-
<p><strong>Registrado:</strong> {{user.registered}}</p>
|
|
9
|
-
</div>
|
|
10
|
-
|
|
11
|
-
<a href="/users">Volver a la lista de usuarios</a>
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ejemplo de uso del sistema MVC con definición de rutas desde archivo JSON
|
|
3
|
-
* Demostración de vistas, helpers y filtros
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const { APIServer, RouteLoader, ControllerLoader, ViewEngine } = require('../../index');
|
|
7
|
-
|
|
8
|
-
// Crear instancia del servidor
|
|
9
|
-
const server = new APIServer({
|
|
10
|
-
port: 9001,
|
|
11
|
-
host: 'localhost'
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
// Crear instancia del cargador de rutas
|
|
15
|
-
const routeLoader = new RouteLoader();
|
|
16
|
-
|
|
17
|
-
// Cargar las rutas desde el archivo JSON
|
|
18
|
-
routeLoader.loadRoutes(server, './examples/mvc_routes_example/routes.json')
|
|
19
|
-
.then(routes => {
|
|
20
|
-
console.log(`${routes.length} rutas cargadas exitosamente`);
|
|
21
|
-
console.log('Rutas disponibles:');
|
|
22
|
-
console.log('- http://localhost:9001/ (Página de inicio)');
|
|
23
|
-
console.log('- http://localhost:9001/users (Lista de usuarios)');
|
|
24
|
-
console.log('- http://localhost:9001/profile?id=1 (Perfil de usuario)');
|
|
25
|
-
console.log('- http://localhost:9001/products (Catálogo de productos)');
|
|
26
|
-
|
|
27
|
-
// Iniciar el servidor
|
|
28
|
-
server.start(() => {
|
|
29
|
-
console.log('Servidor MVC con rutas JSON iniciado en http://localhost:9001');
|
|
30
|
-
});
|
|
31
|
-
})
|
|
32
|
-
.catch(error => {
|
|
33
|
-
console.error('Error al cargar las rutas:', error);
|
|
34
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
const { ControllerBase } = require('../../../index');
|
|
2
|
-
|
|
3
|
-
class MainController extends ControllerBase {
|
|
4
|
-
constructor(options = {}) {
|
|
5
|
-
super(options);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
index(req, res) {
|
|
9
|
-
this.set('title', 'Inicio - Ejemplo MVC con Routes');
|
|
10
|
-
this.set('message', '¡Bienvenido al ejemplo de MVC con definición de rutas!');
|
|
11
|
-
|
|
12
|
-
this.render(res, 'main/index', {
|
|
13
|
-
currentTime: new Date().toISOString(),
|
|
14
|
-
version: '2.3.1'
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Exportar métodos directamente para que el RouteLoader pueda acceder a ellos
|
|
20
|
-
const controllerInstance = new MainController({ viewsPath: './examples/mvc_routes_example/views' });
|
|
21
|
-
|
|
22
|
-
module.exports = {
|
|
23
|
-
index: (req, res) => {
|
|
24
|
-
controllerInstance.setRequestResponse(req, res);
|
|
25
|
-
controllerInstance.index(req, res);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
const { ControllerBase } = require('../../../index');
|
|
2
|
-
|
|
3
|
-
class ProductController extends ControllerBase {
|
|
4
|
-
constructor(options = {}) {
|
|
5
|
-
super(options);
|
|
6
|
-
|
|
7
|
-
// Registrar helpers personalizados para este controlador
|
|
8
|
-
this.getViewEngine().addHelper('calculateDiscount', (price, discountPercent) => {
|
|
9
|
-
return price - (price * discountPercent / 100);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
this.getViewEngine().addHelper('formatCurrency', (value, symbol = '$') => {
|
|
13
|
-
return `${symbol}${Number(value).toFixed(2)}`;
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
this.getViewEngine().addHelper('isOnSale', (product) => {
|
|
17
|
-
return product.discount > 0;
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
catalog(req, res) {
|
|
22
|
-
const products = [
|
|
23
|
-
{ id: 1, name: 'Laptop Pro', price: 1200, discount: 10, category: 'Electronics' },
|
|
24
|
-
{ id: 2, name: 'Mouse Inalámbrico', price: 25, discount: 15, category: 'Accessories' },
|
|
25
|
-
{ id: 3, name: 'Teclado Mecánico', price: 80, discount: 0, category: 'Accessories' },
|
|
26
|
-
{ id: 4, name: 'Monitor 4K', price: 400, discount: 20, category: 'Electronics' },
|
|
27
|
-
{ id: 5, name: 'Auriculares', price: 150, discount: 5, category: 'Audio' }
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
this.set('title', 'Catálogo de Productos');
|
|
31
|
-
this.set('products', products);
|
|
32
|
-
|
|
33
|
-
this.render(res, 'product/catalog', {
|
|
34
|
-
currencySymbol: 'USD'
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Exportar métodos directamente para que el RouteLoader pueda acceder a ellos
|
|
40
|
-
const controllerInstance = new ProductController({ viewsPath: './examples/mvc_routes_example/views' });
|
|
41
|
-
|
|
42
|
-
module.exports = {
|
|
43
|
-
catalog: (req, res) => {
|
|
44
|
-
controllerInstance.setRequestResponse(req, res);
|
|
45
|
-
controllerInstance.catalog(req, res);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
const { ControllerBase } = require('../../../index');
|
|
2
|
-
|
|
3
|
-
class UserController extends ControllerBase {
|
|
4
|
-
constructor(options = {}) {
|
|
5
|
-
super(options);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
list(req, res) {
|
|
9
|
-
const users = [
|
|
10
|
-
{ id: 1, name: 'Ana García', email: 'ana@example.com', registered: '2026-01-01', active: true },
|
|
11
|
-
{ id: 2, name: 'Carlos López', email: 'carlos@example.com', registered: '2026-01-02', active: false },
|
|
12
|
-
{ id: 3, name: 'Laura Martínez', email: 'laura@example.com', registered: '2026-01-03', active: true },
|
|
13
|
-
{ id: 4, name: 'Pedro Rodríguez', email: 'pedro@example.com', registered: '2026-01-04', active: true },
|
|
14
|
-
{ id: 5, name: 'María Sánchez', email: 'maria@example.com', registered: '2026-01-05', active: false }
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
this.set('title', 'Lista de Usuarios');
|
|
18
|
-
this.set('users', users);
|
|
19
|
-
|
|
20
|
-
this.render(res, 'user/list', {
|
|
21
|
-
totalUsers: users.length
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
profile(req, res) {
|
|
26
|
-
const userIdParam = this.input('id', '1');
|
|
27
|
-
|
|
28
|
-
// Validar que el ID sea un número entero positivo
|
|
29
|
-
if (!/^\d+$/.test(userIdParam) || parseInt(userIdParam) <= 0) {
|
|
30
|
-
this.set('title', 'ID de usuario inválido');
|
|
31
|
-
this.render(res, 'user/invalid', {
|
|
32
|
-
userId: userIdParam
|
|
33
|
-
});
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const userId = parseInt(userIdParam);
|
|
38
|
-
|
|
39
|
-
const users = [
|
|
40
|
-
{ id: 1, name: 'Ana García', email: 'ana@example.com', registered: '2026-01-01', active: true },
|
|
41
|
-
{ id: 2, name: 'Carlos López', email: 'carlos@example.com', registered: '2026-01-02', active: false },
|
|
42
|
-
{ id: 3, name: 'Laura Martínez', email: 'laura@example.com', registered: '2026-01-03', active: true },
|
|
43
|
-
{ id: 4, name: 'Pedro Rodríguez', email: 'pedro@example.com', registered: '2026-01-04', active: true },
|
|
44
|
-
{ id: 5, name: 'María Sánchez', email: 'maria@example.com', registered: '2026-01-05', active: false }
|
|
45
|
-
];
|
|
46
|
-
|
|
47
|
-
const user = users.find(u => u.id === userId);
|
|
48
|
-
|
|
49
|
-
if (!user) {
|
|
50
|
-
this.set('title', 'Usuario no encontrado');
|
|
51
|
-
this.render(res, 'user/notfound', {
|
|
52
|
-
userId: userId
|
|
53
|
-
});
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
this.set('title', `Perfil de ${user.name}`);
|
|
58
|
-
this.set('user', user);
|
|
59
|
-
|
|
60
|
-
this.render(res, 'user/profile');
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Exportar métodos directamente para que el RouteLoader pueda acceder a ellos
|
|
65
|
-
const controllerInstance = new UserController({ viewsPath: './examples/mvc_routes_example/views' });
|
|
66
|
-
|
|
67
|
-
module.exports = {
|
|
68
|
-
list: (req, res) => {
|
|
69
|
-
controllerInstance.setRequestResponse(req, res);
|
|
70
|
-
controllerInstance.list(req, res);
|
|
71
|
-
},
|
|
72
|
-
profile: (req, res) => {
|
|
73
|
-
controllerInstance.setRequestResponse(req, res);
|
|
74
|
-
controllerInstance.profile(req, res);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"method": "GET",
|
|
4
|
-
"path": "/",
|
|
5
|
-
"controller": "./examples/mvc_routes_example/controllers/mainController.js",
|
|
6
|
-
"handler": "index",
|
|
7
|
-
"auth": "none"
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
"method": "GET",
|
|
11
|
-
"path": "/users",
|
|
12
|
-
"controller": "./examples/mvc_routes_example/controllers/userController.js",
|
|
13
|
-
"handler": "list",
|
|
14
|
-
"auth": "none"
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"method": "GET",
|
|
18
|
-
"path": "/profile",
|
|
19
|
-
"controller": "./examples/mvc_routes_example/controllers/userController.js",
|
|
20
|
-
"handler": "profile",
|
|
21
|
-
"auth": "none"
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"method": "GET",
|
|
25
|
-
"path": "/products",
|
|
26
|
-
"controller": "./examples/mvc_routes_example/controllers/productController.js",
|
|
27
|
-
"handler": "catalog",
|
|
28
|
-
"auth": "none"
|
|
29
|
-
}
|
|
30
|
-
]
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="es">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>{{title}}</title>
|
|
7
|
-
<style>
|
|
8
|
-
body { font-family: Arial, sans-serif; margin: 40px; background-color: #f5f5f5; }
|
|
9
|
-
.container { max-width: 800px; margin: 0 auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
|
|
10
|
-
h1 { color: #333; }
|
|
11
|
-
nav { margin: 20px 0; }
|
|
12
|
-
nav a { margin-right: 15px; text-decoration: none; color: #007bff; }
|
|
13
|
-
nav a:hover { text-decoration: underline; }
|
|
14
|
-
</style>
|
|
15
|
-
</head>
|
|
16
|
-
<body>
|
|
17
|
-
<div class="container">
|
|
18
|
-
<h1>{{title}}</h1>
|
|
19
|
-
<p>{{message}}</p>
|
|
20
|
-
|
|
21
|
-
<nav>
|
|
22
|
-
<a href="/">Inicio</a>
|
|
23
|
-
<a href="/users">Usuarios</a>
|
|
24
|
-
<a href="/products">Productos</a>
|
|
25
|
-
</nav>
|
|
26
|
-
|
|
27
|
-
<p>Versión: {{version}}</p>
|
|
28
|
-
<p>Hora actual: {{currentTime}}</p>
|
|
29
|
-
</div>
|
|
30
|
-
</body>
|
|
31
|
-
</html>
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
<h1>{{title}}</h1>
|
|
2
|
-
|
|
3
|
-
{{if products}}
|
|
4
|
-
<div class="product-grid">
|
|
5
|
-
{{foreach:products}}
|
|
6
|
-
<div class="product-card">
|
|
7
|
-
<h3>{{item.name}}</h3>
|
|
8
|
-
<p>Categoría: {{item.category}}</p>
|
|
9
|
-
<p>Precio original: {{formatCurrency(item.price)}}</p>
|
|
10
|
-
<p>Descuento: {{item.discount}}%</p>
|
|
11
|
-
{{if item.discount > 0}}
|
|
12
|
-
<p>Precio con descuento: {{formatCurrency(calculateDiscount(item.price, item.discount))}}</p>
|
|
13
|
-
<p class="onsale">¡En oferta!</p>
|
|
14
|
-
{{else}}
|
|
15
|
-
<p class="regular">Precio regular</p>
|
|
16
|
-
{{endif}}
|
|
17
|
-
</div>
|
|
18
|
-
{{endforeach}}
|
|
19
|
-
</div>
|
|
20
|
-
{{else}}
|
|
21
|
-
<p>No hay productos disponibles.</p>
|
|
22
|
-
{{endif}}
|
|
23
|
-
|
|
24
|
-
<a href="/">Volver al inicio</a>
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
<h1>{{title}}</h1>
|
|
2
|
-
|
|
3
|
-
{{if users}}
|
|
4
|
-
<p>Total de usuarios: {{totalUsers}}</p>
|
|
5
|
-
|
|
6
|
-
<table>
|
|
7
|
-
<thead>
|
|
8
|
-
<tr>
|
|
9
|
-
<th>ID</th>
|
|
10
|
-
<th>Nombre</th>
|
|
11
|
-
<th>Email</th>
|
|
12
|
-
<th>Registrado</th>
|
|
13
|
-
<th>Estado</th>
|
|
14
|
-
<th>Acciones</th>
|
|
15
|
-
</tr>
|
|
16
|
-
</thead>
|
|
17
|
-
<tbody>
|
|
18
|
-
{{foreach:users}}
|
|
19
|
-
<tr>
|
|
20
|
-
<td>{{item.id}}</td>
|
|
21
|
-
<td>{{item.name}}</td>
|
|
22
|
-
<td>{{item.email}}</td>
|
|
23
|
-
<td>{{item.registered|date:'DD/MM/YYYY'}}</td>
|
|
24
|
-
<td>
|
|
25
|
-
{{if item.active}}
|
|
26
|
-
<span class="active">Activo</span>
|
|
27
|
-
{{else}}
|
|
28
|
-
<span class="inactive">Inactivo</span>
|
|
29
|
-
{{endif}}
|
|
30
|
-
</td>
|
|
31
|
-
<td><a href="/profile?id={{item.id}}">Ver Perfil</a></td>
|
|
32
|
-
</tr>
|
|
33
|
-
{{endforeach}}
|
|
34
|
-
</tbody>
|
|
35
|
-
</table>
|
|
36
|
-
{{else}}
|
|
37
|
-
<p>No hay usuarios registrados.</p>
|
|
38
|
-
{{endif}}
|
|
39
|
-
|
|
40
|
-
<a href="/">Volver al inicio</a>
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
<h1>{{title}}</h1>
|
|
2
|
-
|
|
3
|
-
<div>
|
|
4
|
-
<h2>Información del Usuario</h2>
|
|
5
|
-
<p><strong>ID:</strong> {{user.id}}</p>
|
|
6
|
-
<p><strong>Nombre:</strong> {{user.name}}</p>
|
|
7
|
-
<p><strong>Email:</strong> {{user.email}}</p>
|
|
8
|
-
<p><strong>Registrado:</strong> {{user.registered|date:'DD/MM/YYYY'}}</p>
|
|
9
|
-
<p><strong>Estado:</strong>
|
|
10
|
-
{{if user.active}}
|
|
11
|
-
<span class="active">Activo</span>
|
|
12
|
-
{{else}}
|
|
13
|
-
<span class="inactive">Inactivo</span>
|
|
14
|
-
{{endif}}
|
|
15
|
-
</p>
|
|
16
|
-
</div>
|
|
17
|
-
|
|
18
|
-
<a href="/users">Volver a la lista de usuarios</a>
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# Ejemplo de Página de Bienvenida con Motor MVC
|
|
2
|
-
|
|
3
|
-
Este ejemplo demuestra cómo usar el motor de plantillas MVC del framework JERK para crear una página de bienvenida atractiva y funcional.
|
|
4
|
-
|
|
5
|
-
## Características
|
|
6
|
-
|
|
7
|
-
- **Sistema MVC**: Uso completo del sistema de vistas, controladores y modelos
|
|
8
|
-
- **Motor de Plantillas**: Uso del motor de plantillas con soporte para variables, condicionales y bucles
|
|
9
|
-
- **Vistas Dinámicas**: Renderizado de contenido dinámico desde el controlador
|
|
10
|
-
- **Estilos Modernos**: Diseño responsive y atractivo
|
|
11
|
-
|
|
12
|
-
## Componentes
|
|
13
|
-
|
|
14
|
-
- `app.js`: Archivo principal que configura el servidor y las rutas
|
|
15
|
-
- `controllers/welcomeController.js`: Controlador que maneja la lógica del sitio
|
|
16
|
-
- `views/home/welcome.html`: Vista principal con el diseño de la página de bienvenida
|
|
17
|
-
|
|
18
|
-
## Uso
|
|
19
|
-
|
|
20
|
-
1. Inicia el servidor:
|
|
21
|
-
```bash
|
|
22
|
-
node examples/mvc_welcome/app.js
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
2. Visita http://localhost:9002 para ver la página de bienvenida
|
|
26
|
-
|
|
27
|
-
## Características del Framework
|
|
28
|
-
|
|
29
|
-
Este ejemplo muestra algunas de las características clave del framework JERK:
|
|
30
|
-
|
|
31
|
-
- Motor de plantillas MVC profesional
|
|
32
|
-
- Sistema de vistas con soporte para variables, condicionales y bucles
|
|
33
|
-
- Controladores MVC con acceso fácil a vistas
|
|
34
|
-
- Arquitectura modular y extensible
|