milkio 0.2.12 → 0.2.13

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.
@@ -18,6 +18,7 @@ export type ExecuteHttpServerOptions = {
18
18
  * @returns
19
19
  */
20
20
  executeIdGenerator?: (request: Request) => string | Promise<string>;
21
+ getRealIp?: (request: Request) => string;
21
22
  };
22
23
 
23
24
  export function defineHttpHandler(app: MilkioApp, options: ExecuteHttpServerOptions = {}) {
@@ -26,7 +27,7 @@ export function defineHttpHandler(app: MilkioApp, options: ExecuteHttpServerOpti
26
27
  const executeId = (options?.executeIdGenerator ? await options.executeIdGenerator(request.request) : createUlid()) as ExecuteId;
27
28
  runtime.execute.executeIds.add(executeId);
28
29
  const logger = useLogger(executeId);
29
- const ip = (request.request.headers.get("x-forwarded-for") as string | undefined)?.split(",")[0] ?? "0.0.0.0";
30
+ const ip = options.getRealIp ? options.getRealIp(request.request) : (request.request.headers.get("X-Forwarded-For") as string | undefined)?.split(",")[0] ?? "0.0.0.0";
30
31
  const headers = request.request.headers;
31
32
 
32
33
  loggerPushTags(executeId, {
package/kernel/logger.ts CHANGED
@@ -23,10 +23,10 @@ export type Logger = {
23
23
  };
24
24
 
25
25
  export const loggerController = (() => {
26
- const logs = new Map<ExecuteId, { __LOG_DEATIL__: Array<LoggerItem>; [key: string]: any }>();
26
+ const logs = new Map<ExecuteId, { __LOG_DETAIL__: Array<LoggerItem>; [key: string]: any }>();
27
27
 
28
28
  const loggerPushTags = (executeId: ExecuteId, tags: Record<string, any>) => {
29
- if (!logs.has(executeId)) logs.set(executeId, { __LOG_DEATIL__: [] });
29
+ if (!logs.has(executeId)) logs.set(executeId, { __LOG_DETAIL__: [] });
30
30
  const logItem = logs.get(executeId);
31
31
  for (const key in tags) {
32
32
  logItem![key] = tags[key];
@@ -41,11 +41,11 @@ export const loggerController = (() => {
41
41
  };
42
42
  const log = logs.get(executeId)!;
43
43
  for (const key in log) {
44
- if (key === "__LOG_DEATIL__") continue;
44
+ if (key === "__LOG_DETAIL__") continue;
45
45
  loggerSubmitOptions[key] = log[key];
46
46
  }
47
47
  logs.delete(executeId);
48
- loggerOptions.onSubmit(loggerSubmitOptions, log.__LOG_DEATIL__);
48
+ loggerOptions.onSubmit(loggerSubmitOptions, log.__LOG_DETAIL__);
49
49
  };
50
50
 
51
51
  const loggerSubmitAll = async () => {
@@ -63,7 +63,7 @@ export const loggerController = (() => {
63
63
  }
64
64
 
65
65
  for (const executeId of executeIds) {
66
- if (!logs.has(executeId as ExecuteId)) logs.set(executeId as ExecuteId, { __LOG_DEATIL__: [] });
66
+ if (!logs.has(executeId as ExecuteId)) logs.set(executeId as ExecuteId, { __LOG_DETAIL__: [] });
67
67
  const loggerItem = {
68
68
  executeId: executeId as ExecuteId,
69
69
  loggerLevel: level,
@@ -71,7 +71,7 @@ export const loggerController = (() => {
71
71
  params,
72
72
  } satisfies LoggerItem;
73
73
  if (!loggerOptions.onInsert(loggerItem)) return;
74
- logs.get(executeId as ExecuteId)!.__LOG_DEATIL__.push(loggerItem);
74
+ logs.get(executeId as ExecuteId)!.__LOG_DETAIL__.push(loggerItem);
75
75
  }
76
76
  };
77
77
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "milkio",
3
3
  "type": "module",
4
4
  "module": "index.ts",
5
- "version": "0.2.12",
5
+ "version": "0.2.13",
6
6
  "peerDependencies": {
7
7
  "typescript": "^5.4.2"
8
8
  },