@desaubv/quik 0.0.4 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +804 -0
- package/dist/cron/index.cjs +330 -0
- package/dist/cron/index.cjs.map +1 -0
- package/dist/cron/index.d.cts +38 -0
- package/dist/cron/index.d.ts +38 -0
- package/dist/cron/index.js +291 -0
- package/dist/cron/index.js.map +1 -0
- package/dist/cron-BLi976po.d.cts +38 -0
- package/dist/cron-BLi976po.d.ts +38 -0
- package/dist/http/index.cjs +99 -0
- package/dist/http/index.cjs.map +1 -0
- package/dist/http/index.d.cts +64 -0
- package/dist/http/index.d.ts +64 -0
- package/dist/http/index.js +72 -0
- package/dist/http/index.js.map +1 -0
- package/dist/index.cjs +190 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -10
- package/dist/index.d.ts +22 -10
- package/dist/index.js +185 -54
- package/dist/index.js.map +1 -1
- package/package.json +63 -51
package/dist/index.d.cts
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import express, { Router as Router$1, RequestHandler, Express } from 'express';
|
|
2
2
|
import { Server as Server$1 } from 'node:http';
|
|
3
|
+
import { Q as QuikCron } from './cron-BLi976po.cjs';
|
|
4
|
+
|
|
5
|
+
declare class ServerInvalidRouteError extends Error {
|
|
6
|
+
constructor(path: string);
|
|
7
|
+
}
|
|
3
8
|
|
|
4
9
|
type ConfigValue = string | null | false;
|
|
5
10
|
type Cases = "uppercase" | "lowercase" | "capitalize" | "none" | null;
|
|
6
11
|
type ColorName = "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white";
|
|
7
12
|
type ColorValue = ColorName | null;
|
|
8
13
|
type SaveConfig = {
|
|
14
|
+
infoFilePath: ConfigValue;
|
|
9
15
|
logFilePath: ConfigValue;
|
|
10
16
|
errorFilePath: ConfigValue;
|
|
11
17
|
warningFilePath: ConfigValue;
|
|
12
18
|
};
|
|
13
19
|
type ColorConfig = {
|
|
14
20
|
logColor: ColorValue;
|
|
21
|
+
infoColor: ColorValue;
|
|
15
22
|
errorColor: ColorValue;
|
|
16
23
|
warningColor: ColorValue;
|
|
17
24
|
debugColor: ColorValue;
|
|
@@ -21,8 +28,10 @@ type Formatconfig = {
|
|
|
21
28
|
titleCase: Cases;
|
|
22
29
|
prefix?: string;
|
|
23
30
|
suffix?: string;
|
|
31
|
+
timeZone?: string;
|
|
24
32
|
};
|
|
25
33
|
type LoggerConfig = {
|
|
34
|
+
language: Language;
|
|
26
35
|
save: SaveConfig;
|
|
27
36
|
color: ColorConfig;
|
|
28
37
|
format: Formatconfig;
|
|
@@ -36,13 +45,15 @@ declare const logger: {
|
|
|
36
45
|
setConfig(newConfig: PartialConfig): void;
|
|
37
46
|
config(): Readonly<LoggerConfig>;
|
|
38
47
|
log(...content: unknown[]): void;
|
|
48
|
+
info(...content: unknown[]): void;
|
|
39
49
|
error(...content: unknown[]): void;
|
|
40
50
|
warning(...content: unknown[]): void;
|
|
41
51
|
debug(...content: unknown[]): void;
|
|
52
|
+
clear(): void;
|
|
42
53
|
custom(level: string, color: ColorName | null | false, file: ConfigValue, ...content: unknown[]): void;
|
|
43
54
|
};
|
|
44
55
|
|
|
45
|
-
declare class
|
|
56
|
+
declare class QuikRouter {
|
|
46
57
|
readonly router: Router$1;
|
|
47
58
|
private pendingMiddleware;
|
|
48
59
|
private currentPath;
|
|
@@ -56,9 +67,8 @@ declare class QuickRouter {
|
|
|
56
67
|
patch(handler: RequestHandler): this;
|
|
57
68
|
delete(handler: RequestHandler): this;
|
|
58
69
|
}
|
|
59
|
-
declare function Router():
|
|
70
|
+
declare function Router(): QuikRouter;
|
|
60
71
|
|
|
61
|
-
type Language = "en" | "es";
|
|
62
72
|
type JsonOptions = Parameters<typeof express.json>[0];
|
|
63
73
|
type UrlencodedOptions = Parameters<typeof express.urlencoded>[0];
|
|
64
74
|
type RawOptions = Parameters<typeof express.raw>[0];
|
|
@@ -89,25 +99,27 @@ type ExpressConfig = {
|
|
|
89
99
|
};
|
|
90
100
|
type QuikServerConfig = {
|
|
91
101
|
language: Language;
|
|
102
|
+
timeZone?: string;
|
|
92
103
|
bodyParser: BodyParserConfig;
|
|
93
104
|
http: HTTPConfig;
|
|
94
105
|
express: ExpressConfig;
|
|
95
106
|
};
|
|
96
|
-
type RoutingDict = Record<string,
|
|
107
|
+
type RoutingDict = Record<string, QuikRouter>;
|
|
97
108
|
declare class QuikServer {
|
|
98
109
|
#private;
|
|
99
110
|
app: Express;
|
|
100
|
-
|
|
111
|
+
httpServer: Server$1;
|
|
101
112
|
middlewares: RequestHandler[];
|
|
102
113
|
routes: RoutingDict;
|
|
114
|
+
crons: QuikCron[];
|
|
103
115
|
config: QuikServerConfig;
|
|
104
116
|
constructor();
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
117
|
+
setConfig(config: Partial<QuikServerConfig>): this;
|
|
118
|
+
addMiddleware(...middlewares: RequestHandler[]): this;
|
|
119
|
+
addRoute(path: string, router: QuikRouter): this;
|
|
120
|
+
addCron(cron: QuikCron): this;
|
|
109
121
|
start(): this;
|
|
110
122
|
}
|
|
111
123
|
declare function Server(): QuikServer;
|
|
112
124
|
|
|
113
|
-
export {
|
|
125
|
+
export { QuikRouter, Router, Server, ServerInvalidRouteError, logger };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import express, { Router as Router$1, RequestHandler, Express } from 'express';
|
|
2
2
|
import { Server as Server$1 } from 'node:http';
|
|
3
|
+
import { Q as QuikCron } from './cron-BLi976po.js';
|
|
4
|
+
|
|
5
|
+
declare class ServerInvalidRouteError extends Error {
|
|
6
|
+
constructor(path: string);
|
|
7
|
+
}
|
|
3
8
|
|
|
4
9
|
type ConfigValue = string | null | false;
|
|
5
10
|
type Cases = "uppercase" | "lowercase" | "capitalize" | "none" | null;
|
|
6
11
|
type ColorName = "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white";
|
|
7
12
|
type ColorValue = ColorName | null;
|
|
8
13
|
type SaveConfig = {
|
|
14
|
+
infoFilePath: ConfigValue;
|
|
9
15
|
logFilePath: ConfigValue;
|
|
10
16
|
errorFilePath: ConfigValue;
|
|
11
17
|
warningFilePath: ConfigValue;
|
|
12
18
|
};
|
|
13
19
|
type ColorConfig = {
|
|
14
20
|
logColor: ColorValue;
|
|
21
|
+
infoColor: ColorValue;
|
|
15
22
|
errorColor: ColorValue;
|
|
16
23
|
warningColor: ColorValue;
|
|
17
24
|
debugColor: ColorValue;
|
|
@@ -21,8 +28,10 @@ type Formatconfig = {
|
|
|
21
28
|
titleCase: Cases;
|
|
22
29
|
prefix?: string;
|
|
23
30
|
suffix?: string;
|
|
31
|
+
timeZone?: string;
|
|
24
32
|
};
|
|
25
33
|
type LoggerConfig = {
|
|
34
|
+
language: Language;
|
|
26
35
|
save: SaveConfig;
|
|
27
36
|
color: ColorConfig;
|
|
28
37
|
format: Formatconfig;
|
|
@@ -36,13 +45,15 @@ declare const logger: {
|
|
|
36
45
|
setConfig(newConfig: PartialConfig): void;
|
|
37
46
|
config(): Readonly<LoggerConfig>;
|
|
38
47
|
log(...content: unknown[]): void;
|
|
48
|
+
info(...content: unknown[]): void;
|
|
39
49
|
error(...content: unknown[]): void;
|
|
40
50
|
warning(...content: unknown[]): void;
|
|
41
51
|
debug(...content: unknown[]): void;
|
|
52
|
+
clear(): void;
|
|
42
53
|
custom(level: string, color: ColorName | null | false, file: ConfigValue, ...content: unknown[]): void;
|
|
43
54
|
};
|
|
44
55
|
|
|
45
|
-
declare class
|
|
56
|
+
declare class QuikRouter {
|
|
46
57
|
readonly router: Router$1;
|
|
47
58
|
private pendingMiddleware;
|
|
48
59
|
private currentPath;
|
|
@@ -56,9 +67,8 @@ declare class QuickRouter {
|
|
|
56
67
|
patch(handler: RequestHandler): this;
|
|
57
68
|
delete(handler: RequestHandler): this;
|
|
58
69
|
}
|
|
59
|
-
declare function Router():
|
|
70
|
+
declare function Router(): QuikRouter;
|
|
60
71
|
|
|
61
|
-
type Language = "en" | "es";
|
|
62
72
|
type JsonOptions = Parameters<typeof express.json>[0];
|
|
63
73
|
type UrlencodedOptions = Parameters<typeof express.urlencoded>[0];
|
|
64
74
|
type RawOptions = Parameters<typeof express.raw>[0];
|
|
@@ -89,25 +99,27 @@ type ExpressConfig = {
|
|
|
89
99
|
};
|
|
90
100
|
type QuikServerConfig = {
|
|
91
101
|
language: Language;
|
|
102
|
+
timeZone?: string;
|
|
92
103
|
bodyParser: BodyParserConfig;
|
|
93
104
|
http: HTTPConfig;
|
|
94
105
|
express: ExpressConfig;
|
|
95
106
|
};
|
|
96
|
-
type RoutingDict = Record<string,
|
|
107
|
+
type RoutingDict = Record<string, QuikRouter>;
|
|
97
108
|
declare class QuikServer {
|
|
98
109
|
#private;
|
|
99
110
|
app: Express;
|
|
100
|
-
|
|
111
|
+
httpServer: Server$1;
|
|
101
112
|
middlewares: RequestHandler[];
|
|
102
113
|
routes: RoutingDict;
|
|
114
|
+
crons: QuikCron[];
|
|
103
115
|
config: QuikServerConfig;
|
|
104
116
|
constructor();
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
117
|
+
setConfig(config: Partial<QuikServerConfig>): this;
|
|
118
|
+
addMiddleware(...middlewares: RequestHandler[]): this;
|
|
119
|
+
addRoute(path: string, router: QuikRouter): this;
|
|
120
|
+
addCron(cron: QuikCron): this;
|
|
109
121
|
start(): this;
|
|
110
122
|
}
|
|
111
123
|
declare function Server(): QuikServer;
|
|
112
124
|
|
|
113
|
-
export {
|
|
125
|
+
export { QuikRouter, Router, Server, ServerInvalidRouteError, logger };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
// src/errors/serverError.ts
|
|
2
|
+
var ServerInvalidRouteError = class extends Error {
|
|
3
|
+
constructor(path2) {
|
|
4
|
+
super(`"${path2}" is not a QuikRouter instance.`);
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
var ServerInvalidCronError = class extends Error {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(`Invalid object, must be a QuikCron instance.`);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
1
13
|
// src/core/logger.ts
|
|
2
14
|
import fs from "fs";
|
|
3
15
|
import path from "path";
|
|
@@ -24,37 +36,118 @@ var colors = Object.fromEntries(
|
|
|
24
36
|
);
|
|
25
37
|
|
|
26
38
|
// src/core/time.ts
|
|
27
|
-
function dateToString(date, format) {
|
|
39
|
+
function dateToString(date, format, timeZone) {
|
|
40
|
+
const formatter = new Intl.DateTimeFormat("en-US", {
|
|
41
|
+
timeZone,
|
|
42
|
+
year: "numeric",
|
|
43
|
+
month: "2-digit",
|
|
44
|
+
day: "2-digit",
|
|
45
|
+
hour: "2-digit",
|
|
46
|
+
minute: "2-digit",
|
|
47
|
+
second: "2-digit",
|
|
48
|
+
hourCycle: "h23"
|
|
49
|
+
});
|
|
50
|
+
const parts = formatter.formatToParts(date);
|
|
51
|
+
const values = Object.fromEntries(
|
|
52
|
+
parts.filter(({ type }) => type !== "literal").map(({ type, value }) => [type, value])
|
|
53
|
+
);
|
|
28
54
|
return format.replace(/(YYYY|MM|DD|hh|mm|ss)/g, (match) => {
|
|
29
55
|
switch (match) {
|
|
30
56
|
case "YYYY":
|
|
31
|
-
return
|
|
57
|
+
return values.year || "";
|
|
32
58
|
case "MM":
|
|
33
|
-
return
|
|
59
|
+
return values.month || "";
|
|
34
60
|
case "DD":
|
|
35
|
-
return
|
|
61
|
+
return values.day || "";
|
|
36
62
|
case "hh":
|
|
37
|
-
return
|
|
63
|
+
return values.hour || "";
|
|
38
64
|
case "mm":
|
|
39
|
-
return
|
|
65
|
+
return values.minute || "";
|
|
40
66
|
case "ss":
|
|
41
|
-
return
|
|
67
|
+
return values.second || "";
|
|
42
68
|
default:
|
|
43
69
|
return match;
|
|
44
70
|
}
|
|
45
71
|
});
|
|
46
72
|
}
|
|
73
|
+
function isValidTimeZone(timeZone) {
|
|
74
|
+
try {
|
|
75
|
+
new Intl.DateTimeFormat("en-US", {
|
|
76
|
+
timeZone
|
|
77
|
+
});
|
|
78
|
+
return true;
|
|
79
|
+
} catch {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// src/locales/en.json
|
|
85
|
+
var en_default = {
|
|
86
|
+
logger: {
|
|
87
|
+
levels: {
|
|
88
|
+
log: "log",
|
|
89
|
+
info: "info",
|
|
90
|
+
warning: "warning",
|
|
91
|
+
error: "error",
|
|
92
|
+
debug: "debug"
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
server: {
|
|
96
|
+
name: "server",
|
|
97
|
+
start: "Server running at",
|
|
98
|
+
routers_loaded: "routers loaded",
|
|
99
|
+
crons_loaded: "crons loaded"
|
|
100
|
+
},
|
|
101
|
+
time: {
|
|
102
|
+
invalidTimeZone1: "Invalid time zone:",
|
|
103
|
+
invalidTimeZone2: "Using system default time zone."
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// src/locales/es.json
|
|
108
|
+
var es_default = {
|
|
109
|
+
logger: {
|
|
110
|
+
levels: {
|
|
111
|
+
log: "log",
|
|
112
|
+
info: "info",
|
|
113
|
+
warning: "advertencia",
|
|
114
|
+
error: "error",
|
|
115
|
+
debug: "depuraci\xF3n"
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
server: {
|
|
119
|
+
name: "servidor",
|
|
120
|
+
start: "Servidor corriendo en",
|
|
121
|
+
routers_loaded: "rutas cargadas",
|
|
122
|
+
crons_loaded: "crons cargados"
|
|
123
|
+
},
|
|
124
|
+
time: {
|
|
125
|
+
invalidTimeZone1: "Zona horaria inv\xE1lida:",
|
|
126
|
+
invalidTimeZone2: "Usando la zona horaria predeterminada del sistema."
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// src/core/translator.ts
|
|
131
|
+
var locales = {
|
|
132
|
+
en: en_default,
|
|
133
|
+
es: es_default
|
|
134
|
+
};
|
|
135
|
+
function translate(language, key) {
|
|
136
|
+
return locales[language][key];
|
|
137
|
+
}
|
|
47
138
|
|
|
48
139
|
// src/core/logger.ts
|
|
49
140
|
var defaultConfig = {
|
|
141
|
+
language: "en",
|
|
50
142
|
save: {
|
|
51
143
|
logFilePath: null,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
warningFilePath:
|
|
144
|
+
infoFilePath: null,
|
|
145
|
+
errorFilePath: "logs/error.log",
|
|
146
|
+
warningFilePath: "logs/warning.log"
|
|
55
147
|
},
|
|
56
148
|
color: {
|
|
57
149
|
logColor: "blue",
|
|
150
|
+
infoColor: "green",
|
|
58
151
|
errorColor: "red",
|
|
59
152
|
warningColor: "yellow",
|
|
60
153
|
debugColor: null
|
|
@@ -99,7 +192,17 @@ function write(level, color2, file, ...content) {
|
|
|
99
192
|
function parseContent(level, ...body) {
|
|
100
193
|
let header = "";
|
|
101
194
|
if (config.format.timestampFormat) {
|
|
102
|
-
const
|
|
195
|
+
const now = /* @__PURE__ */ new Date();
|
|
196
|
+
const timeZone = config.format.timeZone;
|
|
197
|
+
let tz = timeZone;
|
|
198
|
+
if (timeZone && !isValidTimeZone(timeZone)) {
|
|
199
|
+
tz = void 0;
|
|
200
|
+
}
|
|
201
|
+
const timestamp = dateToString(
|
|
202
|
+
now,
|
|
203
|
+
config.format.timestampFormat,
|
|
204
|
+
tz
|
|
205
|
+
);
|
|
103
206
|
header += `${timestamp} `;
|
|
104
207
|
}
|
|
105
208
|
switch (config.format.titleCase) {
|
|
@@ -131,6 +234,8 @@ function saveToFile(filePath, content) {
|
|
|
131
234
|
}
|
|
132
235
|
function mergeConfig(current, update) {
|
|
133
236
|
return {
|
|
237
|
+
...current,
|
|
238
|
+
...update,
|
|
134
239
|
save: {
|
|
135
240
|
...current.save,
|
|
136
241
|
...update.save
|
|
@@ -155,37 +260,53 @@ var logger = {
|
|
|
155
260
|
return Object.freeze(structuredClone(config));
|
|
156
261
|
},
|
|
157
262
|
log(...content) {
|
|
263
|
+
const messages = translate(config.language, "logger");
|
|
158
264
|
write(
|
|
159
|
-
|
|
265
|
+
messages.levels.log,
|
|
160
266
|
config.color.logColor,
|
|
161
267
|
config.save.logFilePath,
|
|
162
268
|
...content
|
|
163
269
|
);
|
|
164
270
|
},
|
|
271
|
+
info(...content) {
|
|
272
|
+
const messages = translate(config.language, "logger");
|
|
273
|
+
write(
|
|
274
|
+
messages.levels.info,
|
|
275
|
+
config.color.infoColor,
|
|
276
|
+
config.save.infoFilePath,
|
|
277
|
+
...content
|
|
278
|
+
);
|
|
279
|
+
},
|
|
165
280
|
error(...content) {
|
|
281
|
+
const messages = translate(config.language, "logger");
|
|
166
282
|
write(
|
|
167
|
-
|
|
283
|
+
messages.levels.error,
|
|
168
284
|
config.color.errorColor,
|
|
169
285
|
config.save.errorFilePath,
|
|
170
286
|
...content
|
|
171
287
|
);
|
|
172
288
|
},
|
|
173
289
|
warning(...content) {
|
|
290
|
+
const messages = translate(config.language, "logger");
|
|
174
291
|
write(
|
|
175
|
-
|
|
292
|
+
messages.levels.warning,
|
|
176
293
|
config.color.warningColor,
|
|
177
294
|
config.save.warningFilePath,
|
|
178
295
|
...content
|
|
179
296
|
);
|
|
180
297
|
},
|
|
181
298
|
debug(...content) {
|
|
299
|
+
const messages = translate(config.language, "logger");
|
|
182
300
|
write(
|
|
183
|
-
|
|
301
|
+
messages.levels.debug,
|
|
184
302
|
config.color.debugColor,
|
|
185
303
|
null,
|
|
186
304
|
...content
|
|
187
305
|
);
|
|
188
306
|
},
|
|
307
|
+
clear() {
|
|
308
|
+
console.clear();
|
|
309
|
+
},
|
|
189
310
|
custom(level, color2, file, ...content) {
|
|
190
311
|
write(level, color2, file, ...content);
|
|
191
312
|
}
|
|
@@ -193,7 +314,7 @@ var logger = {
|
|
|
193
314
|
|
|
194
315
|
// src/core/router.ts
|
|
195
316
|
import { Router as ExpressRouter } from "express";
|
|
196
|
-
var
|
|
317
|
+
var QuikRouter = class {
|
|
197
318
|
router;
|
|
198
319
|
pendingMiddleware = [];
|
|
199
320
|
currentPath = "";
|
|
@@ -241,37 +362,16 @@ var QuickRouter = class {
|
|
|
241
362
|
}
|
|
242
363
|
};
|
|
243
364
|
function Router() {
|
|
244
|
-
return new
|
|
365
|
+
return new QuikRouter();
|
|
245
366
|
}
|
|
246
367
|
|
|
247
368
|
// src/core/server.ts
|
|
248
369
|
import express from "express";
|
|
249
370
|
import http from "http";
|
|
250
371
|
|
|
251
|
-
// src/
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
name: "server",
|
|
255
|
-
start: "Server running at"
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
// src/locales/es.json
|
|
260
|
-
var es_default = {
|
|
261
|
-
server: {
|
|
262
|
-
name: "servidor",
|
|
263
|
-
start: "Servidor corriendo en"
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
// src/core/translator.ts
|
|
268
|
-
var locales = {
|
|
269
|
-
en: en_default,
|
|
270
|
-
es: es_default
|
|
271
|
-
};
|
|
272
|
-
function translate(language, key) {
|
|
273
|
-
return locales[language][key];
|
|
274
|
-
}
|
|
372
|
+
// src/cron/cron.ts
|
|
373
|
+
import cron from "node-cron";
|
|
374
|
+
import "node-cron";
|
|
275
375
|
|
|
276
376
|
// src/core/server.ts
|
|
277
377
|
var defaultConfig2 = {
|
|
@@ -286,18 +386,19 @@ var defaultConfig2 = {
|
|
|
286
386
|
};
|
|
287
387
|
var QuikServer = class {
|
|
288
388
|
app;
|
|
289
|
-
|
|
389
|
+
httpServer;
|
|
290
390
|
middlewares = [];
|
|
291
391
|
routes = {};
|
|
392
|
+
crons = [];
|
|
292
393
|
config;
|
|
293
394
|
constructor() {
|
|
294
395
|
this.app = express();
|
|
295
396
|
this.config = structuredClone(defaultConfig2);
|
|
296
|
-
this.
|
|
397
|
+
this.httpServer = http.createServer(
|
|
297
398
|
this.app
|
|
298
399
|
);
|
|
299
400
|
}
|
|
300
|
-
|
|
401
|
+
setConfig(config2) {
|
|
301
402
|
this.config = {
|
|
302
403
|
...this.config,
|
|
303
404
|
...config2,
|
|
@@ -310,38 +411,56 @@ var QuikServer = class {
|
|
|
310
411
|
...config2.express
|
|
311
412
|
}
|
|
312
413
|
};
|
|
414
|
+
if (config2.timeZone && !isValidTimeZone(config2.timeZone)) {
|
|
415
|
+
const messages = translate(this.config.language, "time");
|
|
416
|
+
logger.warning(
|
|
417
|
+
`${messages.invalidTimeZone1} ${config2.timeZone}. ${messages.invalidTimeZone2}`
|
|
418
|
+
);
|
|
419
|
+
}
|
|
313
420
|
return this;
|
|
314
421
|
}
|
|
315
|
-
|
|
422
|
+
addMiddleware(...middlewares) {
|
|
316
423
|
this.middlewares.push(
|
|
317
424
|
...middlewares
|
|
318
425
|
);
|
|
319
426
|
return this;
|
|
320
427
|
}
|
|
321
|
-
|
|
428
|
+
addRoute(path2, router) {
|
|
429
|
+
if (!(router instanceof QuikRouter)) {
|
|
430
|
+
throw new ServerInvalidRouteError(path2);
|
|
431
|
+
}
|
|
432
|
+
if (!path2.startsWith("/"))
|
|
433
|
+
path2 = "/" + path2;
|
|
322
434
|
this.routes[path2] = router;
|
|
323
435
|
return this;
|
|
324
436
|
}
|
|
325
|
-
listen() {
|
|
437
|
+
#listen() {
|
|
326
438
|
const { port, host } = this.config.http;
|
|
327
439
|
const messages = translate(this.config.language, "server");
|
|
328
|
-
this.
|
|
440
|
+
this.httpServer.listen(
|
|
329
441
|
port,
|
|
330
442
|
host,
|
|
331
443
|
() => {
|
|
332
|
-
logger.
|
|
444
|
+
logger.info(`${messages.start} ${host ?? "localhost"}:${port}`);
|
|
333
445
|
}
|
|
334
446
|
);
|
|
335
447
|
return this;
|
|
336
448
|
}
|
|
449
|
+
addCron(cron2) {
|
|
450
|
+
if (cron2.constructor.name != "QuikCron") {
|
|
451
|
+
throw new ServerInvalidCronError();
|
|
452
|
+
}
|
|
453
|
+
this.crons.push(cron2);
|
|
454
|
+
return this;
|
|
455
|
+
}
|
|
337
456
|
#configureHTTP() {
|
|
338
457
|
const config2 = this.config.http;
|
|
339
458
|
if (config2.timeout)
|
|
340
|
-
this.
|
|
459
|
+
this.httpServer.timeout = config2.timeout;
|
|
341
460
|
if (config2.keepAlive)
|
|
342
|
-
this.
|
|
461
|
+
this.httpServer.keepAliveTimeout = config2.keepAlive;
|
|
343
462
|
if (config2.maxConnections)
|
|
344
|
-
this.
|
|
463
|
+
this.httpServer.maxConnections = config2.maxConnections;
|
|
345
464
|
return this;
|
|
346
465
|
}
|
|
347
466
|
#configureExpress() {
|
|
@@ -389,14 +508,25 @@ var QuikServer = class {
|
|
|
389
508
|
router.router
|
|
390
509
|
);
|
|
391
510
|
}
|
|
511
|
+
const messages = translate(this.config.language, "server");
|
|
512
|
+
logger.info(`[ ROUTER ] ${Object.entries(this.routes).length} ${messages.routers_loaded}.`);
|
|
513
|
+
return this;
|
|
514
|
+
}
|
|
515
|
+
#loadCrons() {
|
|
516
|
+
for (const cron2 of this.crons) {
|
|
517
|
+
cron2.start();
|
|
518
|
+
}
|
|
519
|
+
const messages = translate(this.config.language, "server");
|
|
520
|
+
logger.info(`[ CRON ] ${this.crons.length} ${messages.crons_loaded}.`);
|
|
392
521
|
return this;
|
|
393
522
|
}
|
|
394
523
|
start() {
|
|
395
524
|
this.#configureExpress();
|
|
396
525
|
this.#configureMiddleware();
|
|
397
526
|
this.#configureRoutes();
|
|
527
|
+
this.#loadCrons();
|
|
398
528
|
this.#configureHTTP();
|
|
399
|
-
this
|
|
529
|
+
this.#listen();
|
|
400
530
|
return this;
|
|
401
531
|
}
|
|
402
532
|
};
|
|
@@ -404,9 +534,10 @@ function Server() {
|
|
|
404
534
|
return new QuikServer();
|
|
405
535
|
}
|
|
406
536
|
export {
|
|
407
|
-
|
|
537
|
+
QuikRouter,
|
|
408
538
|
Router,
|
|
409
539
|
Server,
|
|
540
|
+
ServerInvalidRouteError,
|
|
410
541
|
logger
|
|
411
542
|
};
|
|
412
543
|
//# sourceMappingURL=index.js.map
|