@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.
@@ -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
  }
@@ -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
  }
@@ -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
  }
@@ -125,6 +125,10 @@ export declare namespace XHandler {
125
125
  * 请求路径
126
126
  */
127
127
  requestPath?: OneOrMore<string>;
128
+ /**
129
+ * 解析请求数据
130
+ */
131
+ parseRequestData?: (data: any, ctx: Context) => any;
128
132
  /**
129
133
  * 是否打包返回数据
130
134
  *
@@ -1,7 +1,8 @@
1
- import { BasePlugin } from './base';
1
+ import { FastifyCorsOptions } from '@fastify/cors';
2
2
  import { FastifyInstance } from 'fastify';
3
3
  import { MsValue } from 'vtils';
4
- export interface CorsPluginOptions {
4
+ import { BasePlugin } from './base';
5
+ export interface CorsPluginOptions extends FastifyCorsOptions {
5
6
  /**
6
7
  * 允许的来源,支持位于开头的 * 通配符
7
8
  */
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.52.0",
3
+ "version": "2.52.2",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",