@x-9lab/xlab 1.0.0 → 1.0.4-alpha.1

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.
Files changed (37) hide show
  1. package/@types/components/{common.d.ts → common/index.d.ts} +6 -35
  2. package/@types/components/{cron.d.ts → cron/index.d.ts} +0 -0
  3. package/@types/components/html-processor/index.d.ts +1 -1
  4. package/@types/components/index.d.ts +42 -0
  5. package/@types/components/{log.d.ts → log/index.d.ts} +0 -0
  6. package/@types/components/request/index.d.ts +51 -0
  7. package/@types/components/request/resolve-uri.d.ts +6 -0
  8. package/@types/components/{return-code.d.ts → return-code/index.d.ts} +0 -0
  9. package/@types/components/uuid/index.d.ts +2 -0
  10. package/@types/default-x-config.d.ts +6 -0
  11. package/@types/global.d.ts +15 -22
  12. package/README.md +45 -0
  13. package/dist/bin/watch.js +2 -1
  14. package/dist/bin/xlab +35 -26
  15. package/dist/components/{common.js → common/index.js} +22 -86
  16. package/dist/components/{cron.js → cron/index.js} +0 -0
  17. package/dist/components/html-processor/index.js +4 -4
  18. package/dist/components/index.js +4 -0
  19. package/dist/components/{log.js → log/index.js} +0 -0
  20. package/dist/components/request/index.js +157 -0
  21. package/dist/components/request/resolve-uri.js +28 -0
  22. package/dist/components/{return-code.js → return-code/index.js} +0 -0
  23. package/dist/components/uuid/index.js +14 -7
  24. package/dist/config/process-custom-config-files.js +4 -3
  25. package/dist/config/process-def-config-file.js +6 -4
  26. package/dist/custom.js +2 -1
  27. package/dist/default-x-config.js +21 -0
  28. package/dist/global.js +3 -2
  29. package/dist/middleware/service-mark.js +7 -3
  30. package/dist/middlewares.js +7 -1
  31. package/dist/router.js +2 -1
  32. package/dist/server.js +2 -1
  33. package/package.json +12 -14
  34. package/@types/components/combo/index.d.ts +0 -4
  35. package/@types/middleware/combo.d.ts +0 -2
  36. package/dist/components/combo/index.js +0 -170
  37. package/dist/middleware/combo.js +0 -13
@@ -1,5 +1,7 @@
1
1
  /// <reference types="node" />
2
+ import { sleep, labelReplace, fix0, numberFormat } from "@x-drive/utils";
2
3
  import fs from "fs";
4
+ export { labelReplace, fix0, numberFormat, sleep };
3
5
  /**
4
6
  * ascii字符串转为base64字符串
5
7
  * @param str 要转化的字符串
@@ -22,56 +24,24 @@ export { base64Toascii };
22
24
  */
23
25
  declare function params(dat: Record<string, any>, url: string): string;
24
26
  export { params };
25
- /**
26
- * 按位数格式化数字
27
- * @param val 要格式化的数字
28
- * @param separator 分割符
29
- * @param size 分割位数间隔
30
- * @return 格式化完的字符串
31
- */
32
- declare function numberFormat(val: number, separator: string, size: number): string;
33
- export { numberFormat };
34
- /**
35
- * 批量替换字符串中带花括号标签为指定数据
36
- * @param tpl 待处理的字符串
37
- * @param data 替换数据
38
- * @return 替换后端字符串
39
- */
40
- declare function labelReplace(tpl: string, data: Record<string, XLab.JsonValue>): string;
41
- /**
42
- * 批量替换字符串中带花括号标签为指定数据
43
- * @param tpl 待处理的字符串
44
- * @param data 替换数据
45
- * @return 替换后端字符串
46
- */
47
- declare function labelReplace(tpl: string, data: XLab.JsonValue): string;
48
- export { labelReplace };
49
- /**
50
- * 格式化数字, 自动补0前续
51
- * @param number 要格式化的数字
52
- * @param size 格式化后出来的数字位数
53
- * @return 格式化结果
54
- */
55
- declare function fix0(number: number, size: number): string;
56
- export { fix0 };
57
27
  /**
58
28
  * 格式化时间
59
29
  * @param format 日期格式
60
- * @param date 时间戳
30
+ * @param ts 时间戳
61
31
  * @return 格式化后的时间
62
32
  */
63
33
  declare function date(format: string, ts: number): string;
64
34
  /**
65
35
  * 格式化时间
66
36
  * @param format 日期格式
67
- * @param date 日期字符串
37
+ * @param ts 日期字符串
68
38
  * @return 格式化后的时间
69
39
  */
70
40
  declare function date(format: string, ts: string): string;
71
41
  /**
72
42
  * 格式化时间
73
43
  * @param format 日期格式
74
- * @param date 日期对象
44
+ * @param ts 日期对象
75
45
  * @return 格式化后的时间
76
46
  */
77
47
  declare function date(format: string, ts: Date): string;
@@ -125,6 +95,7 @@ declare function promiseWapper(...args: any[]): Promise<unknown>;
125
95
  export { promiseWapper };
126
96
  /**
127
97
  * 封装一个 promise 形式的 request 方法
98
+ * @deprecated 请直接使用 component 中的 request 模块
128
99
  */
129
100
  declare function requestWapper<T = any>(...args: any[]): Promise<unknown>;
130
101
  export { requestWapper };
File without changes
@@ -1,5 +1,5 @@
1
1
  import type Koa from "koa";
2
- declare type RouteOption = Record<string, string | string[]>;
2
+ declare type RouteOption = Record<string, string | string[] | Function>;
3
3
  interface HtmlProcessorOptions {
4
4
  route?: RouteOption;
5
5
  }
@@ -0,0 +1,42 @@
1
+ /**内置组件 */
2
+ interface InternalComponents {
3
+ /**资产 */
4
+ assets: typeof import("./assets");
5
+ /**缓存 */
6
+ cache: typeof import("./cache");
7
+ /**cluster */
8
+ cluster: typeof import("./cluster");
9
+ /**Http header 相关 */
10
+ header: typeof import("./header");
11
+ /**Html 内容处理器 */
12
+ "html-processor": typeof import("./html-processor");
13
+ /**JS 内容处理器 */
14
+ "js-processor": typeof import("./js-processor");
15
+ /**数据注入 */
16
+ injection: typeof import("./injection");
17
+ /**MD5 */
18
+ md5: typeof import("./md5");
19
+ /**MIME */
20
+ mime: typeof import("./mime");
21
+ /**客户端判断 */
22
+ platform: typeof import("./platform");
23
+ /**请求参数处理 */
24
+ querystring: typeof import("./querystring");
25
+ /**各种重定向方法 */
26
+ redirect: typeof import("./redirect");
27
+ /**简单的 uuid */
28
+ uuid: typeof import("./uuid");
29
+ /**版本比对 */
30
+ version: typeof import("./version");
31
+ /**定时任务 */
32
+ cron: typeof import("./cron");
33
+ /**日志 */
34
+ log: typeof import("./log");
35
+ /**业务返回码 */
36
+ "return-code": typeof import("./return-code");
37
+ /**通用工具函数集 */
38
+ common: typeof import("./common");
39
+ /**内部请求模块 */
40
+ request: typeof import("./request");
41
+ }
42
+ export type { InternalComponents };
File without changes
@@ -0,0 +1,51 @@
1
+ import type { RequestInit, Response } from "node-fetch";
2
+ /**支持的返回数据类型 */
3
+ declare type IFetchType = "text" | "json" | "blob" | "buffer" | "arrayBuffer";
4
+ /**请求配置 */
5
+ interface IFetchConfig extends Partial<Omit<RequestInit, "body" | "method">> {
6
+ /**数据返回类型 */
7
+ type?: IFetchType;
8
+ /**是否强制同源 */
9
+ sameOrigin?: boolean;
10
+ /**请求自动重试次数 */
11
+ retry?: number;
12
+ /**自动重试间隔时间 */
13
+ retryDelay?: number;
14
+ /**是否自动追加随机数retry,默认 false */
15
+ random?: boolean;
16
+ /**数据返回时的钩子 */
17
+ onResponse?: (res?: Response) => Promise<unknown>;
18
+ }
19
+ export type { IFetchConfig };
20
+ /**给指定对象增加一个随机字符串 */
21
+ declare function setRandomStr(query: any): void;
22
+ export { setRandomStr };
23
+ /**设置默认 Headers */
24
+ declare function setDefHeaders(headers: Record<string, any>): void;
25
+ export { setDefHeaders };
26
+ /**
27
+ * 获取数据
28
+ * @param type 请求类型
29
+ * @param uri 请求地址
30
+ * @param query 请求参数
31
+ * @param data 发送数据
32
+ * @param config 请求配置
33
+ * @param needProcessConfig 是否需要处理配置
34
+ */
35
+ declare function httpFetch<T = unknown>(type: string, uri: string, query?: Record<string, any>, data?: any, config?: IFetchConfig, retry?: number, needProcessConfig?: boolean): Promise<T>;
36
+ export { httpFetch as fetch };
37
+ /**
38
+ * 发起一个 get 请求
39
+ * @param uri 请求地址
40
+ * @param query 请求参数
41
+ */
42
+ declare function requsetGet<T = unknown>(uri: string, query?: Record<string, any>, config?: IFetchConfig): Promise<T>;
43
+ export { requsetGet as get };
44
+ /**
45
+ * 发起一个 post 请求
46
+ * @param uri 请求地址
47
+ * @param query 请求参数
48
+ * @param data 请求数据
49
+ */
50
+ declare function requestPost<T>(uri: string, query?: any, data?: any, config?: IFetchConfig): Promise<T>;
51
+ export { requestPost as post };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 解析请求别名
3
+ * @param uri 请求地址
4
+ */
5
+ declare function resolve(uri: string): string;
6
+ export default resolve;
@@ -1,3 +1,5 @@
1
+ /**当前机器的 mac */
2
+ export declare const X_MAC: string;
1
3
  /**
2
4
  * 生成一个 uuid
3
5
  * @param one 第一节数据
@@ -0,0 +1,6 @@
1
+ declare class Config {
2
+ get businessDir(): string;
3
+ set businessDir(val: string);
4
+ }
5
+ declare const _default: Config;
6
+ export default _default;
@@ -1,27 +1,6 @@
1
+ import type { InternalComponents } from "./components";
1
2
  export type { IPlat } from "./components/platform";
2
3
  import type Koa from "koa";
3
- /**内置组件 */
4
- interface InternalComponents {
5
- assets: typeof import("./components/assets");
6
- cache: typeof import("./components/cache");
7
- cluster: typeof import("./components/cluster");
8
- combo: typeof import("./components/combo");
9
- header: typeof import("./components/header");
10
- "html-processor": typeof import("./components/html-processor");
11
- injection: typeof import("./components/injection");
12
- "js-processor": typeof import("./components/js-processor");
13
- md5: typeof import("./components/md5");
14
- mime: typeof import("./components/mime");
15
- platform: typeof import("./components/platform");
16
- querystring: typeof import("./components/querystring");
17
- redirect: typeof import("./components/redirect");
18
- uuid: typeof import("./components/uuid");
19
- version: typeof import("./components/version");
20
- cron: typeof import("./components/cron");
21
- log: typeof import("./components/log");
22
- "return-code": typeof import("./components/return-code");
23
- common: typeof import("./components/common");
24
- }
25
4
  declare global {
26
5
  /**全局日志对象 */
27
6
  var log: any;
@@ -137,6 +116,10 @@ declare global {
137
116
  strictSSL?: boolean;
138
117
  /**页端注入的 api 设置 */
139
118
  apis?: Record<string, string>;
119
+ /**内部服务域名 */
120
+ internalServers?: Record<string, string>;
121
+ /**内部服务地址 */
122
+ internalApis?: Record<string, string>;
140
123
  /**服务 ip 地址 */
141
124
  ip?: string;
142
125
  /**本地是否存在本地开发配置文件 config.lo.json */
@@ -181,5 +164,15 @@ declare global {
181
164
  }
182
165
  /**业务错误定义 */
183
166
  type ICodeDetail = Record<string, ICodeItem>;
167
+ /**模块配置 */
168
+ interface XConfig {
169
+ /**watch 模式配置 */
170
+ watch?: {
171
+ /**是否启用 watch */
172
+ enable: boolean;
173
+ };
174
+ /**服务端业务目录,默认是 @server */
175
+ businessDir?: string;
176
+ }
184
177
  }
185
178
  }
package/README.md CHANGED
@@ -14,6 +14,10 @@ X-9lab 通用服务端
14
14
  }
15
15
  }
16
16
  ```
17
+ - 配置文件 `xlab.config.js`
18
+ 模块会自动检测执行根目录中是否存在 `xlab.config.js` 文件。如存在该文件则会使用该文件为模块的启动配置文件。支持的配置项:
19
+ 1. `watch` 是否开启 watch 模式
20
+ 1. `business` 业务目录名称。注意当前只支持根目录下的文件夹
17
21
  - `watch` 模式
18
22
  `xlab` 支持自动重启业务,开发中使用该功能可以减少大量手动重启业务的操作。
19
23
  启用方式:
@@ -96,14 +100,55 @@ X-9lab 通用服务端
96
100
  function setSysConfig(conf: XLab.IConfig): void;
97
101
  ```
98
102
  - `requireModel` 全局获取 model 的方法
103
+ 该方法只是为获取 model 提供一个快捷方式,也可以通过正常的方式去 require
104
+ - 存放路径 `business/@models`
105
+ - 使用方式
106
+ ```js
107
+ const { testModel } = requireModel("test");
108
+ ```
109
+ - 类型支持
110
+ 由于 `requireModel` 是一个 `xlab` 的内置方法没有业务本身的 model 定义,因此需要业务方自行追加。出于管理方面的考虑,建议将所有的 model 定义放在一个文件中
111
+ ```ts
112
+ declare global {
113
+ namespace XLab {
114
+ interface IModels {
115
+ /**测试 model */
116
+ test: typeof import("./business/@models/test");
117
+ }
118
+ }
119
+ }
120
+ export { }
121
+ ```
99
122
  - `requireService` 全局获取 service 的方法
123
+ 该方法只是为获取 service 提供一个快捷方式,也可以通过正常的方式去 require
124
+ - 存放路径 `business/@services`
125
+ - 使用方式
126
+ ```js
127
+ const { testFn } = requireService("test");
128
+ ```
129
+ - 类型支持
130
+ 由于 `requireService` 是一个 `xlab` 的内置方法没有业务本身的 service 定义,因此需要业务方自行追加。出于管理方面的考虑,建议将所有的 service 定义放在一个文件中
131
+ ```ts
132
+ declare global {
133
+ namespace XLab {
134
+ interface IServices {
135
+ /**测试 model */
136
+ test: typeof import("./business/@services/test");
137
+ }
138
+ }
139
+ }
140
+ export { }
141
+ ```
100
142
 
101
143
  #### Namespace `XLab`
102
144
  `XLab` 提供了一些标准化的定义及系统配置
103
145
  - `IStdRes` 标准返回数据
104
146
  - `IConfig` 系统配置对象
147
+ - 外部模块追加配置项
105
148
  - `ICodeItem` 错误信息对象
106
149
  - `ICodeDetail` 错误定义
150
+ - `IServices` 业务 services 定义
151
+ - `IModels` 业务 model 定义
107
152
 
108
153
  ### 配置项
109
154
  |名称|类型|默认值|说明|
package/dist/bin/watch.js CHANGED
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ const XConfig = require("../default-x-config");
2
3
  const { date } = require("@x-drive/utils");
3
4
  const crossSpawn = require("cross-spawn");
4
5
  const colors = require("colors/safe");
@@ -107,7 +108,7 @@ const fs = require("fs");
107
108
  if (chokidar) {
108
109
  if (!config.paths) {
109
110
  // 默认业务自定义服务端业务文件夹
110
- const customDir = path.resolve(process.cwd(), "@server");
111
+ const customDir = path.resolve(process.cwd(), XConfig.businessDir);
111
112
  config.paths = [
112
113
  customDir
113
114
  ];
package/dist/bin/xlab CHANGED
@@ -1,14 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const argv = require("minimist")(process.argv.slice(2));
4
- const { merge } = require("@x-drive/utils");
4
+ const { merge, isString } = require("@x-drive/utils");
5
+ const XConfig = require("../default-x-config").default;
5
6
  const Liftoff = require("liftoff");
6
7
 
7
8
  const cli = new Liftoff({
8
9
  "name": "x-lab"
9
10
  , "processTitle": "X Lab"
10
11
  , "moduleName": "xlab"
11
- , "configName": "xlab-config"
12
+ , "configName": "xlab.config"
12
13
  , "extensions": {
13
14
  ".js": null
14
15
  }
@@ -16,34 +17,42 @@ const cli = new Liftoff({
16
17
 
17
18
  const hasWatch = argv.w || argv.watch;
18
19
 
19
- cli.launch(
20
+ function onLaunch(env) {
21
+ /**@type {XLab.XConfig} */
22
+ let config = {
23
+ "watch": {
24
+ "enable": false
25
+ }
26
+ }
27
+ if (env.configPath) {
28
+ try {
29
+ let customConfig = require(env.configPath);
30
+ if (customConfig) {
31
+ merge(config, customConfig);
32
+ }
33
+ } catch (e) { }
34
+ }
35
+ if (isString(config.businessDir)) {
36
+ XConfig.businessDir = config.businessDir;
37
+ }
38
+ if (hasWatch) {
39
+ config.watch.enable = true;
40
+ }
41
+ if (config.watch && config.watch.enable) {
42
+ const watch = require("./watch");
43
+ watch(config.watch);
44
+ } else {
45
+ const server = require("../server");
46
+ server.boot();
47
+ }
48
+ }
49
+
50
+ cli.prepare(
20
51
  {
21
52
  "cwd": argv.r || argv.root
22
53
  , "configPath": argv.f || argv.file
23
54
  }
24
55
  , function (env) {
25
- let config = {
26
- "watch": {
27
- "enable": false
28
- }
29
- }
30
- if (env.configPath) {
31
- try {
32
- let customConfig = require(env.configPath);
33
- if (customConfig) {
34
- merge(config, customConfig);
35
- }
36
- } catch (e) { }
37
- }
38
- if (hasWatch) {
39
- config.watch.enable = true;
40
- }
41
- if (config.watch && config.watch.enable) {
42
- const watch = require("./watch");
43
- watch(config.watch);
44
- } else {
45
- const server = require("../server");
46
- server.boot();
47
- }
56
+ cli.execute(env, onLaunch);
48
57
  }
49
58
  );
@@ -9,12 +9,13 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
+ labelReplace: ()=>_utils.labelReplace,
13
+ fix0: ()=>_utils.fix0,
14
+ numberFormat: ()=>_utils.numberFormat,
15
+ sleep: ()=>_utils.sleep,
12
16
  asciiTobase64: ()=>asciiTobase64,
13
17
  base64Toascii: ()=>base64Toascii,
14
18
  params: ()=>params,
15
- numberFormat: ()=>numberFormat,
16
- labelReplace: ()=>labelReplace,
17
- fix0: ()=>fix0,
18
19
  date: ()=>date,
19
20
  responseResult: ()=>responseResult,
20
21
  getMD5: ()=>getMD5,
@@ -28,10 +29,9 @@ _export(exports, {
28
29
  checkFileStat: ()=>checkFileStat,
29
30
  getRealDefaultMod: ()=>getRealDefaultMod
30
31
  });
31
- const _returnCode = require("./return-code");
32
32
  const _utils = require("@x-drive/utils");
33
+ const _returnCode = require("../return-code");
33
34
  const _querystring = /*#__PURE__*/ _interopRequireDefault(require("querystring"));
34
- const _request = /*#__PURE__*/ _interopRequireDefault(require("request"));
35
35
  const _crypto = /*#__PURE__*/ _interopRequireDefault(require("crypto"));
36
36
  const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
37
37
  const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
@@ -41,6 +41,12 @@ function _interopRequireDefault(obj) {
41
41
  };
42
42
  }
43
43
  var logger;
44
+ function checkLogger() {
45
+ if (!logger) {
46
+ logger = log.getLogger("common");
47
+ }
48
+ return logger;
49
+ }
44
50
  /**
45
51
  * ascii字符串转为base64字符串
46
52
  * @param str 要转化的字符串
@@ -73,73 +79,11 @@ var logger;
73
79
  }
74
80
  return data;
75
81
  }
76
- /**
77
- * 按位数格式化数字
78
- * @param val 要格式化的数字
79
- * @param separator 分割符
80
- * @param size 分割位数间隔
81
- * @return 格式化完的字符串
82
- */ function numberFormat(val, separator, size) {
83
- if (typeof val !== "number") {
84
- return "0";
85
- }
86
- if (!separator) {
87
- separator = ",";
88
- }
89
- if (!size) {
90
- size = 3;
91
- }
92
- var last = size;
93
- const valStr = val.toString();
94
- var pos = valStr.indexOf(".");
95
- var res = "";
96
- if (pos === -1) {
97
- pos = valStr.length;
98
- } else {
99
- res = valStr.substr(pos);
100
- }
101
- if (valStr.charAt(0) === "-") {
102
- last++;
103
- }
104
- while(pos > last){
105
- pos -= size;
106
- res = separator + valStr.substr(pos, size) + res;
107
- }
108
- if (pos) {
109
- res = valStr.substr(0, pos) + res;
110
- }
111
- return res;
112
- }
113
- /**
114
- * 带花括号标签检测正则
115
- */ const labelReplaceExp = /\{(\w+)\}/g;
116
- /**
117
- * 批量替换字符串中带花括号标签为指定数据
118
- * @param tpl 待处理的字符串
119
- * @param data 替换数据
120
- * @return 替换后端字符串
121
- */ function labelReplace(tpl, data) {
122
- return tpl.replace(labelReplaceExp, function(label, key) {
123
- return typeof data === "object" ? data[key] : data;
124
- });
125
- }
126
- /**
127
- * 格式化数字, 自动补0前续
128
- * @param number 要格式化的数字
129
- * @param size 格式化后出来的数字位数
130
- * @return 格式化结果
131
- */ function fix0(number, size) {
132
- var num = number.toString();
133
- while(num.length < size){
134
- num = "0" + num;
135
- }
136
- return num;
137
- }
138
82
  const format_exp = /[YymndjNwaAghGHis]/g;
139
83
  /**
140
84
  * 格式化时间
141
85
  * @param format 日期格式
142
- * @param date 日期数据(时间戳, 字符串)
86
+ * @param ts 日期数据(时间戳, 字符串)
143
87
  * @return 格式化后的时间
144
88
  */ function date(format, ts) {
145
89
  ts = new Date(ts);
@@ -150,11 +94,11 @@ const format_exp = /[YymndjNwaAghGHis]/g;
150
94
  case "y":
151
95
  return ts.getFullYear() % 100;
152
96
  case "m":
153
- return fix0(ts.getMonth() + 1, 2);
97
+ return (0, _utils.fix0)(ts.getMonth() + 1, 2);
154
98
  case "n":
155
99
  return ts.getMonth() + 1;
156
100
  case "d":
157
- return fix0(ts.getDate(), 2);
101
+ return (0, _utils.fix0)(ts.getDate(), 2);
158
102
  case "j":
159
103
  return ts.getDate();
160
104
  case "N":
@@ -168,15 +112,15 @@ const format_exp = /[YymndjNwaAghGHis]/g;
168
112
  case "g":
169
113
  return ts.getHours() % 12 + 1;
170
114
  case "h":
171
- return fix0(ts.getHours() % 12 + 1, 2);
115
+ return (0, _utils.fix0)(ts.getHours() % 12 + 1, 2);
172
116
  case "G":
173
117
  return ts.getHours();
174
118
  case "H":
175
- return fix0(ts.getHours(), 2);
119
+ return (0, _utils.fix0)(ts.getHours(), 2);
176
120
  case "i":
177
- return fix0(ts.getMinutes(), 2);
121
+ return (0, _utils.fix0)(ts.getMinutes(), 2);
178
122
  case "s":
179
- return fix0(ts.getSeconds(), 2);
123
+ return (0, _utils.fix0)(ts.getSeconds(), 2);
180
124
  }
181
125
  return tag;
182
126
  });
@@ -241,16 +185,10 @@ const format_exp = /[YymndjNwaAghGHis]/g;
241
185
  }
242
186
  /**
243
187
  * 封装一个 promise 形式的 request 方法
188
+ * @deprecated 请直接使用 component 中的 request 模块
244
189
  */ function requestWapper(...args) {
245
- return new Promise(function(resolve, reject) {
246
- args.push(function(err, res, body) {
247
- if (err) {
248
- reject(err);
249
- } else {
250
- resolve(body);
251
- }
252
- });
253
- _request.default.apply(_request.default, args);
190
+ return new Promise(function(_, reject) {
191
+ reject(new Error("请直接使用 component 中的 request 模块"));
254
192
  });
255
193
  }
256
194
  /**
@@ -262,9 +200,7 @@ const format_exp = /[YymndjNwaAghGHis]/g;
262
200
  try {
263
201
  re = JSON.parse(data);
264
202
  } catch (err) {
265
- if (!logger) {
266
- log.getLogger("common");
267
- }
203
+ checkLogger();
268
204
  logger.error("Pares create menu return data fail.", data);
269
205
  return null;
270
206
  }
File without changes
@@ -39,7 +39,7 @@ function processorVar(html, req) {
39
39
  // 设置缓存头
40
40
  // 根据配置设置相应头部
41
41
  function htmlProcessor(pathname, options, context) {
42
- var filename = _path.default.resolve(conf.root + pathname);
42
+ var filename = _path.default.resolve(conf.root, pathname);
43
43
  // ua = req.get('user-agent'),
44
44
  var cacheKey;
45
45
  var html;
@@ -55,11 +55,11 @@ function htmlProcessor(pathname, options, context) {
55
55
  try {
56
56
  html = html_cache.get(cacheKey);
57
57
  if (!html) {
58
- html = _fs.default.readFileSync(filename, 'utf8');
58
+ html = _fs.default.readFileSync(filename, "utf8");
59
59
  html_cache.set(cacheKey, html);
60
60
  }
61
61
  } catch (e) {
62
- logger.error('HTML Process Error', e);
62
+ logger.error("HTML Process Error", e);
63
63
  return null;
64
64
  }
65
65
  // 无法正确读取 HTML
@@ -79,7 +79,7 @@ function htmlProcessor(pathname, options, context) {
79
79
  Object.keys(headers).forEach((key)=>{
80
80
  let val;
81
81
  if ((0, _utils.isFunction)(headers[key])) {
82
- val = headers[key].call();
82
+ val = headers[key]();
83
83
  } else {
84
84
  val = headers[key];
85
85
  }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
File without changes