@jayfong/x-server 2.9.1 → 2.9.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/lib/_cjs/core/server.js +3 -1
- package/lib/_cjs/plugins/cors.js +2 -2
- package/lib/_cjs/plugins/file_parser.js +2 -2
- package/lib/_cjs/plugins/xml_parser.js +3 -4
- package/lib/_cjs/services/redis.js +2 -4
- package/lib/core/server.js +3 -1
- package/lib/core/types.d.ts +1 -1
- package/lib/plugins/cors.js +1 -1
- package/lib/plugins/file_parser.d.ts +1 -1
- package/lib/plugins/file_parser.js +1 -1
- package/lib/plugins/form_body_parser.d.ts +2 -2
- package/lib/plugins/xml_parser.d.ts +2 -2
- package/lib/plugins/xml_parser.js +3 -2
- package/lib/services/redis.d.ts +2 -2
- package/lib/services/redis.js +1 -1
- package/package.json +15 -16
package/lib/_cjs/core/server.js
CHANGED
|
@@ -46,7 +46,9 @@ class Server {
|
|
|
46
46
|
async prepareFastify() {
|
|
47
47
|
this.fastify = (0, _fastify.default)({
|
|
48
48
|
logger: process.env.NODE_ENV === 'development' ? {
|
|
49
|
-
|
|
49
|
+
transport: {
|
|
50
|
+
target: 'pino-pretty'
|
|
51
|
+
}
|
|
50
52
|
} : false,
|
|
51
53
|
// 信任 X-Forwarded-For 头以获取正确的 IP,
|
|
52
54
|
// 否则通过 nginx 代理后 remoteAddr 将始终为 127.0.0.1
|
package/lib/_cjs/plugins/cors.js
CHANGED
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
exports.__esModule = true;
|
|
6
6
|
exports.CorsPlugin = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _cors = _interopRequireDefault(require("@fastify/cors"));
|
|
9
9
|
|
|
10
10
|
var _vtils = require("vtils");
|
|
11
11
|
|
|
@@ -34,7 +34,7 @@ class CorsPlugin {
|
|
|
34
34
|
const pass = allows.some(item => item.type === 'equal' ? domain === item.domain : domain.endsWith(item.domain));
|
|
35
35
|
return pass;
|
|
36
36
|
});
|
|
37
|
-
fastify.register(
|
|
37
|
+
fastify.register(_cors.default, {
|
|
38
38
|
origin: (origin, cb) => allowAll ? cb(null, true) : cb(null, origin ? check(origin) : true),
|
|
39
39
|
maxAge: (0, _date.ms)(this.options.ttl, true)
|
|
40
40
|
});
|
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
exports.__esModule = true;
|
|
6
6
|
exports.FileParserPlugin = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _multipart = _interopRequireDefault(require("@fastify/multipart"));
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* file 解析器插件
|
|
@@ -16,7 +16,7 @@ class FileParserPlugin {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
register(fastify) {
|
|
19
|
-
fastify.register(
|
|
19
|
+
fastify.register(_multipart.default, this.options);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
3
|
exports.__esModule = true;
|
|
6
4
|
exports.XmlParserPlugin = void 0;
|
|
7
5
|
|
|
8
|
-
var _fastXmlParser =
|
|
6
|
+
var _fastXmlParser = require("fast-xml-parser");
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
9
|
* XML 解析器插件
|
|
@@ -22,6 +20,7 @@ class XmlParserPlugin {
|
|
|
22
20
|
contentType = ['text/xml', 'application/xml'],
|
|
23
21
|
...parseOptions
|
|
24
22
|
} = this.options || {};
|
|
23
|
+
const xmlParser = new _fastXmlParser.XMLParser(parseOptions);
|
|
25
24
|
fastify.addContentTypeParser(contentType, (req, payload, done) => {
|
|
26
25
|
let body = '';
|
|
27
26
|
|
|
@@ -34,7 +33,7 @@ class XmlParserPlugin {
|
|
|
34
33
|
let err;
|
|
35
34
|
|
|
36
35
|
try {
|
|
37
|
-
data =
|
|
36
|
+
data = xmlParser.parse(body);
|
|
38
37
|
} catch (_err) {
|
|
39
38
|
err = _err;
|
|
40
39
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
3
|
exports.__esModule = true;
|
|
6
4
|
exports.RedisService = void 0;
|
|
7
5
|
|
|
8
|
-
var _ioredis =
|
|
6
|
+
var _ioredis = require("ioredis");
|
|
9
7
|
|
|
10
|
-
class RedisService extends _ioredis.
|
|
8
|
+
class RedisService extends _ioredis.Redis {
|
|
11
9
|
constructor(...args) {
|
|
12
10
|
super(...args);
|
|
13
11
|
this.serviceName = 'redis';
|
package/lib/core/server.js
CHANGED
|
@@ -32,7 +32,9 @@ export class Server {
|
|
|
32
32
|
async prepareFastify() {
|
|
33
33
|
this.fastify = Fastify({
|
|
34
34
|
logger: process.env.NODE_ENV === 'development' ? {
|
|
35
|
-
|
|
35
|
+
transport: {
|
|
36
|
+
target: 'pino-pretty'
|
|
37
|
+
}
|
|
36
38
|
} : false,
|
|
37
39
|
// 信任 X-Forwarded-For 头以获取正确的 IP,
|
|
38
40
|
// 否则通过 nginx 代理后 remoteAddr 将始终为 127.0.0.1
|
package/lib/core/types.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { DisposeService } from '../services/dispose';
|
|
|
9
9
|
import type { Handler } from './handler';
|
|
10
10
|
import type { IncomingHttpHeaders } from 'http';
|
|
11
11
|
import type { MsValue } from 'vtils/date';
|
|
12
|
-
import type { MultipartFile } from 'fastify
|
|
12
|
+
import type { MultipartFile } from '@fastify/multipart';
|
|
13
13
|
import type { Queue } from 'bull';
|
|
14
14
|
import type { SocketStream } from '@fastify/websocket';
|
|
15
15
|
export declare namespace XServer {
|
package/lib/plugins/cors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FastifyMultipartOptions } from 'fastify
|
|
1
|
+
import { FastifyMultipartOptions } from '@fastify/multipart';
|
|
2
2
|
import { BasePlugin } from './base';
|
|
3
3
|
import { FastifyInstance } from 'fastify';
|
|
4
4
|
export interface FileParserPluginOptions extends FastifyMultipartOptions {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FastifyFormbodyOptions } from '@fastify/formbody';
|
|
2
2
|
import { BasePlugin } from './base';
|
|
3
3
|
import { FastifyInstance } from 'fastify';
|
|
4
|
-
export interface FormBodyParserPluginOptions extends
|
|
4
|
+
export interface FormBodyParserPluginOptions extends FastifyFormbodyOptions {
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
7
|
* POST application/x-www-form-urlencoded 解析器插件
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import fxp from 'fast-xml-parser';
|
|
2
1
|
import { BasePlugin } from './base';
|
|
3
2
|
import { FastifyInstance } from 'fastify';
|
|
4
|
-
|
|
3
|
+
import { X2jOptions } from 'fast-xml-parser';
|
|
4
|
+
export interface XmlParserPluginOptions extends Partial<X2jOptions> {
|
|
5
5
|
/**
|
|
6
6
|
* 要处理的 `Content-Type`
|
|
7
7
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { XMLParser } from 'fast-xml-parser';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* XML 解析器插件
|
|
@@ -15,6 +15,7 @@ export class XmlParserPlugin {
|
|
|
15
15
|
contentType = ['text/xml', 'application/xml'],
|
|
16
16
|
...parseOptions
|
|
17
17
|
} = this.options || {};
|
|
18
|
+
const xmlParser = new XMLParser(parseOptions);
|
|
18
19
|
fastify.addContentTypeParser(contentType, (req, payload, done) => {
|
|
19
20
|
let body = '';
|
|
20
21
|
|
|
@@ -27,7 +28,7 @@ export class XmlParserPlugin {
|
|
|
27
28
|
let err;
|
|
28
29
|
|
|
29
30
|
try {
|
|
30
|
-
data =
|
|
31
|
+
data = xmlParser.parse(body);
|
|
31
32
|
} catch (_err) {
|
|
32
33
|
err = _err;
|
|
33
34
|
}
|
package/lib/services/redis.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Redis from 'ioredis';
|
|
2
1
|
import { BaseService } from './base';
|
|
3
|
-
|
|
2
|
+
import { Redis, RedisOptions } from 'ioredis';
|
|
3
|
+
export interface RedisServiceOptions extends RedisOptions {
|
|
4
4
|
}
|
|
5
5
|
export declare class RedisService extends Redis implements BaseService {
|
|
6
6
|
serviceName: string;
|
package/lib/services/redis.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jayfong/x-server",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.3",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "lib/_cjs/index.js",
|
|
@@ -26,10 +26,11 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@fastify/
|
|
30
|
-
"@fastify/
|
|
29
|
+
"@fastify/cors": "^8.3.0",
|
|
30
|
+
"@fastify/formbody": "^7.4.0",
|
|
31
|
+
"@fastify/multipart": "^7.7.0",
|
|
32
|
+
"@fastify/websocket": "^8.1.0",
|
|
31
33
|
"@prisma/client": "^4.8.0",
|
|
32
|
-
"@types/bull": "^3.15.8",
|
|
33
34
|
"@types/busboy": "^0.3.2",
|
|
34
35
|
"@types/cron": "^2.0.0",
|
|
35
36
|
"@types/http-errors": "^1.8.2",
|
|
@@ -38,33 +39,31 @@
|
|
|
38
39
|
"@types/ws": "^8.5.3",
|
|
39
40
|
"alipay-sdk": "^3.2.0",
|
|
40
41
|
"bufferutil": "^4.0.6",
|
|
41
|
-
"bull": "^4.
|
|
42
|
+
"bull": "^4.10.4",
|
|
42
43
|
"chokidar": "^3.5.3",
|
|
43
44
|
"comment-parser": "^1.3.1",
|
|
44
45
|
"compressing": "^1.5.1",
|
|
45
|
-
"cron": "^2.
|
|
46
|
+
"cron": "^2.3.1",
|
|
46
47
|
"cuid": "^2.1.8",
|
|
47
48
|
"debug": "^4.3.4",
|
|
48
49
|
"esbuild": "^0.14.36",
|
|
49
50
|
"esbuild-register": "^3.3.2",
|
|
50
51
|
"execa": "^5.1.1",
|
|
51
52
|
"exit-hook": "^2.2.1",
|
|
52
|
-
"fast-xml-parser": "^
|
|
53
|
-
"fastify": "^
|
|
54
|
-
"fastify-cors": "^6.0.3",
|
|
55
|
-
"fastify-multipart": "^5.3.1",
|
|
53
|
+
"fast-xml-parser": "^4.2.5",
|
|
54
|
+
"fastify": "^4.19.2",
|
|
56
55
|
"fs-extra": "^10.0.1",
|
|
57
56
|
"globby": "^11",
|
|
58
57
|
"got": "^11.8.2",
|
|
59
|
-
"http-errors": "^
|
|
60
|
-
"ioredis": "^
|
|
58
|
+
"http-errors": "^2.0.0",
|
|
59
|
+
"ioredis": "^5.3.2",
|
|
61
60
|
"jsonwebtoken": "^8.5.1",
|
|
62
61
|
"lz-string": "^1.4.4",
|
|
63
62
|
"mini-svg-data-uri": "^1.4.4",
|
|
64
63
|
"mint-filter": "^3.0.1",
|
|
65
64
|
"node-ssh": "^12.0.4",
|
|
66
65
|
"nodemailer": "^6.7.3",
|
|
67
|
-
"pino-pretty": "^
|
|
66
|
+
"pino-pretty": "^10.0.1",
|
|
68
67
|
"prisma": "^4.8.0",
|
|
69
68
|
"select-run": "^1.1.2",
|
|
70
69
|
"supports-color": "^8",
|
|
@@ -78,20 +77,20 @@
|
|
|
78
77
|
"devDependencies": {
|
|
79
78
|
"@types/debug": "^4.1.7",
|
|
80
79
|
"@types/fs-extra": "^9.0.13",
|
|
81
|
-
"@types/ioredis": "^
|
|
80
|
+
"@types/ioredis": "^5.0.0",
|
|
82
81
|
"@types/json-schema": "^7.0.11",
|
|
83
82
|
"@types/lz-string": "^1.3.34",
|
|
84
83
|
"axios": "^1.4.0",
|
|
85
84
|
"eslint": "^7.32.0",
|
|
86
85
|
"haoma": "^3.6.4",
|
|
87
86
|
"husky": "^4.3.8",
|
|
88
|
-
"ioredis-mock": "^
|
|
87
|
+
"ioredis-mock": "^8.7.0",
|
|
89
88
|
"jest": "^27.5.1",
|
|
90
89
|
"lint-staged": "^10.5.4",
|
|
91
90
|
"npm-check-updates": "^12.5.9",
|
|
92
91
|
"prettier": "^2.8.8",
|
|
93
92
|
"standard-version": "^9.3.2",
|
|
94
|
-
"typescript": "^5.
|
|
93
|
+
"typescript": "^5.1.6",
|
|
95
94
|
"typescript-snapshots-plugin": "^1.7.0"
|
|
96
95
|
},
|
|
97
96
|
"publishConfig": {
|