@dnax/core 0.5.2 → 0.5.3
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/app/hono.ts +47 -2
- package/package.json +1 -1
- package/types/index.ts +15 -1
package/app/hono.ts
CHANGED
|
@@ -28,10 +28,55 @@ const API_PATH = "/api";
|
|
|
28
28
|
function HonoInstance(): typeof app {
|
|
29
29
|
if (Cfg?.server?.logger) {
|
|
30
30
|
if (typeof Cfg?.server?.logger == "function") {
|
|
31
|
-
app.use(
|
|
31
|
+
app.use(async (c, next) => {
|
|
32
|
+
const start = Date.now();
|
|
33
|
+
const { action, collection, cleanDeep, useCache } = c.req.query() as Q;
|
|
34
|
+
Cfg.server.logger(c, {
|
|
35
|
+
mode: "incomming",
|
|
36
|
+
start: start,
|
|
37
|
+
action: action,
|
|
38
|
+
collection: collection,
|
|
39
|
+
cleanDeep: cleanDeep,
|
|
40
|
+
useCache: useCache,
|
|
41
|
+
method: c.req.method,
|
|
42
|
+
url: c.req.url,
|
|
43
|
+
});
|
|
44
|
+
await next();
|
|
45
|
+
const duration = Date.now() - start;
|
|
46
|
+
Cfg.server.logger(c, {
|
|
47
|
+
mode: "outgoing",
|
|
48
|
+
duration,
|
|
49
|
+
start,
|
|
50
|
+
action,
|
|
51
|
+
collection,
|
|
52
|
+
cleanDeep,
|
|
53
|
+
useCache,
|
|
54
|
+
method: c.req.method,
|
|
55
|
+
url: c.req.url,
|
|
56
|
+
status: c.res.status,
|
|
57
|
+
});
|
|
58
|
+
});
|
|
32
59
|
}
|
|
33
60
|
if (typeof Cfg?.server?.logger == "boolean") {
|
|
34
|
-
app.use(
|
|
61
|
+
app.use(async (c, next) => {
|
|
62
|
+
const start = Date.now();
|
|
63
|
+
const { action, collection, cleanDeep, useCache } = c.req.query() as Q;
|
|
64
|
+
// Log the incoming request
|
|
65
|
+
console.log(
|
|
66
|
+
`<-- ${c.req.method} /${c.req.url} - C ${collection || ""} - A ${
|
|
67
|
+
action || ""
|
|
68
|
+
}\n`
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
await next();
|
|
72
|
+
// Calculate the duration of the request processing
|
|
73
|
+
const duration = Date.now() - start;
|
|
74
|
+
console.log(
|
|
75
|
+
`--> ${c.req.method} /${c.req.url} - C ${collection || ""} - A ${
|
|
76
|
+
action || ""
|
|
77
|
+
} - ${c.res.status} - (${duration + "".green}ms)\n`
|
|
78
|
+
);
|
|
79
|
+
});
|
|
35
80
|
}
|
|
36
81
|
}
|
|
37
82
|
app.use(
|
package/package.json
CHANGED
package/types/index.ts
CHANGED
|
@@ -294,7 +294,21 @@ export type Collection = {
|
|
|
294
294
|
}>;
|
|
295
295
|
};
|
|
296
296
|
|
|
297
|
-
export type loggerFunction = (
|
|
297
|
+
export type loggerFunction = (
|
|
298
|
+
c: Context,
|
|
299
|
+
ctx: {
|
|
300
|
+
mode: "incomming" | "outgoing";
|
|
301
|
+
start: number;
|
|
302
|
+
action?: string;
|
|
303
|
+
collection?: string;
|
|
304
|
+
cleanDeep?: boolean;
|
|
305
|
+
useCache?: boolean;
|
|
306
|
+
method: string;
|
|
307
|
+
url?: string;
|
|
308
|
+
status?: number;
|
|
309
|
+
duration?: number;
|
|
310
|
+
}
|
|
311
|
+
) => void;
|
|
298
312
|
|
|
299
313
|
export type Config = {
|
|
300
314
|
email?: {
|