/
config.default.ts
75 lines (72 loc) 路 1.34 KB
/
config.default.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import {
Options,
OptionsJson,
OptionsText,
OptionsUrlencoded,
} from 'body-parser';
import { CookieOptions } from 'express';
export const express = {
contextLoggerFormat: info => {
const req = info.ctx;
// format: '[$userId/$ip/$traceId/$use_ms $method $url]'
const userId = req?.['session']?.['userId'] || '-';
const traceId = '-';
const use = Date.now() - info.ctx.startTime;
const label =
userId +
'/' +
req.ip +
'/' +
traceId +
'/' +
use +
'ms ' +
req.method +
' ' +
req.url;
return `${info.timestamp} ${info.LEVEL} ${info.pid} [${label}] ${info.message}`;
},
};
export const cookieParser: {
enable?: boolean;
secret?: string | string[];
options?: CookieOptions;
} = {
enable: true,
};
export const bodyParser: {
enable?: boolean;
json?: OptionsJson & {
enable?: boolean;
};
raw?: Options & {
enable?: boolean;
};
text?: OptionsText & {
enable?: boolean;
};
urlencoded?: OptionsUrlencoded & {
enable?: boolean;
};
} = {
enable: true,
json: {
enable: true,
limit: '1mb',
strict: true,
},
raw: {
enable: false,
limit: '1mb',
},
text: {
enable: true,
limit: '1mb',
},
urlencoded: {
enable: true,
extended: false,
limit: '1mb',
parameterLimit: 1000,
},
};