@jayfong/x-server 2.52.0 → 2.52.2
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/handler.js
CHANGED
|
@@ -31,6 +31,10 @@ class Handler {
|
|
|
31
31
|
return this.handleHttp(data, ctx);
|
|
32
32
|
};
|
|
33
33
|
this.handleHttp = async (data, ctx) => {
|
|
34
|
+
// 请求数据解析
|
|
35
|
+
if (this.options.parseRequestData) {
|
|
36
|
+
data = await this.options.parseRequestData(data, ctx);
|
|
37
|
+
}
|
|
34
38
|
// 请求数据验证
|
|
35
39
|
// vae
|
|
36
40
|
if (this.requestDataSchemaVae) {
|
|
@@ -45,7 +49,6 @@ class Handler {
|
|
|
45
49
|
data = res.data;
|
|
46
50
|
} else {
|
|
47
51
|
throw new _http_error.HttpError.BadRequest(
|
|
48
|
-
// TODO: 暂时兼容编译bug
|
|
49
52
|
// @ts-ignore
|
|
50
53
|
res.issues[0].message);
|
|
51
54
|
}
|
package/lib/_cjs/plugins/cors.js
CHANGED
|
@@ -29,7 +29,8 @@ class CorsPlugin {
|
|
|
29
29
|
});
|
|
30
30
|
fastify.register(_cors.default, {
|
|
31
31
|
origin: (origin, cb) => allowAll ? cb(null, true) : cb(null, origin ? check(origin) : true),
|
|
32
|
-
maxAge: (0, _vtils.ms)(this.options.ttl, true)
|
|
32
|
+
maxAge: (0, _vtils.ms)(this.options.ttl, true),
|
|
33
|
+
...(0, _vtils.omitStrict)(this.options, ['allow', 'ttl'])
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
36
|
}
|
package/lib/core/handler.js
CHANGED
|
@@ -25,6 +25,10 @@ export class Handler {
|
|
|
25
25
|
return this.handleHttp(data, ctx);
|
|
26
26
|
};
|
|
27
27
|
this.handleHttp = async (data, ctx) => {
|
|
28
|
+
// 请求数据解析
|
|
29
|
+
if (this.options.parseRequestData) {
|
|
30
|
+
data = await this.options.parseRequestData(data, ctx);
|
|
31
|
+
}
|
|
28
32
|
// 请求数据验证
|
|
29
33
|
// vae
|
|
30
34
|
if (this.requestDataSchemaVae) {
|
|
@@ -39,7 +43,6 @@ export class Handler {
|
|
|
39
43
|
data = res.data;
|
|
40
44
|
} else {
|
|
41
45
|
throw new HttpError.BadRequest(
|
|
42
|
-
// TODO: 暂时兼容编译bug
|
|
43
46
|
// @ts-ignore
|
|
44
47
|
res.issues[0].message);
|
|
45
48
|
}
|
package/lib/core/types.d.ts
CHANGED
package/lib/plugins/cors.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FastifyCorsOptions } from '@fastify/cors';
|
|
2
2
|
import { FastifyInstance } from 'fastify';
|
|
3
3
|
import { MsValue } from 'vtils';
|
|
4
|
-
|
|
4
|
+
import { BasePlugin } from './base';
|
|
5
|
+
export interface CorsPluginOptions extends FastifyCorsOptions {
|
|
5
6
|
/**
|
|
6
7
|
* 允许的来源,支持位于开头的 * 通配符
|
|
7
8
|
*/
|
package/lib/plugins/cors.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import FastifyCors from '@fastify/cors';
|
|
2
|
-
import { memoize } from 'vtils';
|
|
2
|
+
import { memoize, omitStrict } from 'vtils';
|
|
3
3
|
import { ms } from 'vtils';
|
|
4
4
|
/**
|
|
5
5
|
* CORS 支持插件
|
|
@@ -25,7 +25,8 @@ export class CorsPlugin {
|
|
|
25
25
|
});
|
|
26
26
|
fastify.register(FastifyCors, {
|
|
27
27
|
origin: (origin, cb) => allowAll ? cb(null, true) : cb(null, origin ? check(origin) : true),
|
|
28
|
-
maxAge: ms(this.options.ttl, true)
|
|
28
|
+
maxAge: ms(this.options.ttl, true),
|
|
29
|
+
...omitStrict(this.options, ['allow', 'ttl'])
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
}
|