@dnax/core 0.5.3 → 0.5.5
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 +18 -9
- package/package.json +1 -1
- package/types/index.ts +1 -0
package/app/hono.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Q, Tenant, sessionCtx } from "../types/";
|
|
|
2
2
|
|
|
3
3
|
import { Hono } from "hono";
|
|
4
4
|
import { getCookie, setCookie } from "hono/cookie";
|
|
5
|
-
|
|
5
|
+
import colors from "@colors/colors/safe";
|
|
6
6
|
import { serveStatic, getConnInfo } from "hono/bun";
|
|
7
7
|
import { consola } from "consola";
|
|
8
8
|
import { cors } from "hono/cors";
|
|
@@ -22,12 +22,13 @@ import { getTenant } from "../lib/tenant";
|
|
|
22
22
|
import { checkPermission, getPermission } from "../lib/permissions";
|
|
23
23
|
import { ipRestriction } from "hono/ip-restriction";
|
|
24
24
|
import { logger } from "hono/logger";
|
|
25
|
+
import { v4 } from "uuid";
|
|
25
26
|
const app = new Hono();
|
|
26
27
|
|
|
27
28
|
const API_PATH = "/api";
|
|
28
29
|
function HonoInstance(): typeof app {
|
|
29
30
|
if (Cfg?.server?.logger) {
|
|
30
|
-
if (typeof Cfg?.server?.logger == "function") {
|
|
31
|
+
if (typeof Cfg?.server?.logger == "function" && Cfg?.server?.logger) {
|
|
31
32
|
app.use(async (c, next) => {
|
|
32
33
|
const start = Date.now();
|
|
33
34
|
const { action, collection, cleanDeep, useCache } = c.req.query() as Q;
|
|
@@ -40,6 +41,7 @@ function HonoInstance(): typeof app {
|
|
|
40
41
|
useCache: useCache,
|
|
41
42
|
method: c.req.method,
|
|
42
43
|
url: c.req.url,
|
|
44
|
+
path: c.req.path,
|
|
43
45
|
});
|
|
44
46
|
await next();
|
|
45
47
|
const duration = Date.now() - start;
|
|
@@ -54,27 +56,34 @@ function HonoInstance(): typeof app {
|
|
|
54
56
|
method: c.req.method,
|
|
55
57
|
url: c.req.url,
|
|
56
58
|
status: c.res.status,
|
|
59
|
+
path: c.req.path,
|
|
57
60
|
});
|
|
58
61
|
});
|
|
59
62
|
}
|
|
60
|
-
if (typeof Cfg?.server?.logger == "boolean") {
|
|
63
|
+
if (typeof Cfg?.server?.logger == "boolean" && Cfg?.server?.logger) {
|
|
61
64
|
app.use(async (c, next) => {
|
|
65
|
+
const info = getConnInfo(c);
|
|
66
|
+
if (c.req.method == "OPTIONS") return await next();
|
|
62
67
|
const start = Date.now();
|
|
63
68
|
const { action, collection, cleanDeep, useCache } = c.req.query() as Q;
|
|
64
69
|
// Log the incoming request
|
|
65
70
|
console.log(
|
|
66
|
-
`<-- ${
|
|
67
|
-
|
|
68
|
-
}
|
|
71
|
+
`<-- ${info.remote.address} | ${c.req.method.gray} ${
|
|
72
|
+
c.req.path?.gray
|
|
73
|
+
} -C ${colors.blue(`${collection || ""}`)} -A ${
|
|
74
|
+
action?.gray || ""
|
|
75
|
+
} -T ${moment(start).format("YYYY-DD-MM:HH:mm").gray} \n`
|
|
69
76
|
);
|
|
70
77
|
|
|
71
78
|
await next();
|
|
72
79
|
// Calculate the duration of the request processing
|
|
73
80
|
const duration = Date.now() - start;
|
|
74
81
|
console.log(
|
|
75
|
-
`--> ${
|
|
76
|
-
|
|
77
|
-
} - ${
|
|
82
|
+
`--> ${info.remote.address} | ${c.req.method.gray} ${
|
|
83
|
+
c.req.path?.gray
|
|
84
|
+
} -C ${colors.blue(`${collection || ""}`)} -A ${
|
|
85
|
+
action?.gray || ""
|
|
86
|
+
} -S ${c.res.status} -D ${colors.green(`(${duration}ms)`)}\n`
|
|
78
87
|
);
|
|
79
88
|
});
|
|
80
89
|
}
|
package/package.json
CHANGED