@cicctencent/midwayjs-base 1.0.35 → 1.0.37
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/README.md +347 -1
- package/dist/config/config.default.d.ts +2 -2
- package/dist/config/config.default.js +33 -57
- package/dist/config/env.js +6 -9
- package/dist/configuration.js +26 -38
- package/dist/filter/default.filter.js +5 -9
- package/dist/filter/notfound.filter.js +5 -10
- package/dist/guard/api.d.ts +0 -3
- package/dist/guard/api.js +12 -29
- package/dist/guard/auth.d.ts +0 -3
- package/dist/guard/auth.js +34 -57
- package/dist/index.js +19 -39
- package/dist/lib/decorator.d.ts +3 -33
- package/dist/lib/decorator.js +15 -57
- package/dist/lib/jwt.d.ts +3 -104
- package/dist/lib/jwt.js +8 -24
- package/dist/lib/request.d.ts +0 -5
- package/dist/lib/request.js +3 -7
- package/dist/lib/utils.d.ts +1 -7
- package/dist/lib/utils.js +10 -42
- package/dist/middleware/apiResultFormatter.d.ts +4 -5
- package/dist/middleware/apiResultFormatter.js +26 -30
- package/dist/middleware/detect.middleware.d.ts +3 -4
- package/dist/middleware/detect.middleware.js +14 -20
- package/dist/middleware/requestInit.d.ts +4 -5
- package/dist/middleware/requestInit.js +54 -54
- package/dist/service/session.service.d.ts +1 -25
- package/dist/service/session.service.js +16 -44
- package/dist/service/tencent.service.d.ts +5 -13
- package/dist/service/tencent.service.js +35 -44
- package/dist/types/base.controller.js +5 -12
- package/dist/types/base.model.service.d.ts +1 -9
- package/dist/types/base.model.service.js +5 -19
- package/dist/types/base.service.d.ts +1 -10
- package/dist/types/base.service.js +16 -39
- package/dist/types/session.service.interface.d.ts +1 -15
- package/dist/types/session.service.interface.js +8 -16
- package/package.json +13 -1
package/README.md
CHANGED
|
@@ -1 +1,347 @@
|
|
|
1
|
-
midwayjs
|
|
1
|
+
# @cicctencent/midwayjs-base
|
|
2
|
+
|
|
3
|
+
MidwayJS 基础组件 - 集成公司基础服务能力
|
|
4
|
+
|
|
5
|
+
## 简介
|
|
6
|
+
|
|
7
|
+
`@cicctencent/midwayjs-base` 是一个基于 MidwayJS 框架的企业级基础组件,集成了公司常用的基础服务能力,包括认证授权、文件存储、API 网关、会话管理等功能。
|
|
8
|
+
|
|
9
|
+
## 功能特性
|
|
10
|
+
|
|
11
|
+
### 🔐 认证授权
|
|
12
|
+
- JWT Token 认证
|
|
13
|
+
- 单点登录 (SSO) 集成
|
|
14
|
+
- 接口权限守卫
|
|
15
|
+
- 管理员账号验证
|
|
16
|
+
|
|
17
|
+
### 📁 文件存储
|
|
18
|
+
- 腾讯云 COS 文件上传/下载
|
|
19
|
+
- 文件访问 URL 生成(带临时签名)
|
|
20
|
+
- 多存储桶配置支持
|
|
21
|
+
|
|
22
|
+
### 🔌 API 网关
|
|
23
|
+
- 统一 API 响应格式
|
|
24
|
+
- 请求参数校验
|
|
25
|
+
- IP 白名单控制
|
|
26
|
+
- API Token 验证
|
|
27
|
+
|
|
28
|
+
### 💾 会话管理
|
|
29
|
+
- 分布式会话存储
|
|
30
|
+
- 会话超时配置
|
|
31
|
+
- 自定义会话服务接口
|
|
32
|
+
|
|
33
|
+
### 🛡️ 安全防护
|
|
34
|
+
- 请求检测中间件
|
|
35
|
+
- 异常过滤器
|
|
36
|
+
- 404 处理
|
|
37
|
+
- 统一错误处理
|
|
38
|
+
|
|
39
|
+
## 快速开始
|
|
40
|
+
|
|
41
|
+
### 安装
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm install @cicctencent/midwayjs-base
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 配置
|
|
48
|
+
|
|
49
|
+
在 `src/configuration.ts` 中引入配置:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { Configuration } from '@midwayjs/core';
|
|
53
|
+
import * as base from '@cicctencent/midwayjs-base';
|
|
54
|
+
|
|
55
|
+
@Configuration({
|
|
56
|
+
imports: [
|
|
57
|
+
base
|
|
58
|
+
],
|
|
59
|
+
importConfigs: [
|
|
60
|
+
// 你的配置
|
|
61
|
+
]
|
|
62
|
+
})
|
|
63
|
+
export class MainConfiguration {
|
|
64
|
+
// 配置
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 环境变量配置
|
|
69
|
+
|
|
70
|
+
创建 `.env` 文件:
|
|
71
|
+
|
|
72
|
+
```env
|
|
73
|
+
# 应用配置
|
|
74
|
+
APP_ID=1001
|
|
75
|
+
SERVICE_NAME=your-service-name
|
|
76
|
+
|
|
77
|
+
# API 配置
|
|
78
|
+
API_KEY=your-api-key
|
|
79
|
+
|
|
80
|
+
# SSO 配置
|
|
81
|
+
SSO_URL=https://sso.example.com
|
|
82
|
+
|
|
83
|
+
# 腾讯云配置
|
|
84
|
+
TENCENT_CREDENTIAL_SECRETID=your-secret-id
|
|
85
|
+
TENCENT_CREDENTIAL_SECRETKEY=your-secret-key
|
|
86
|
+
|
|
87
|
+
# 会话配置
|
|
88
|
+
SESSION_TIMEOUT=1200000
|
|
89
|
+
|
|
90
|
+
# 日志配置
|
|
91
|
+
LOG_LEVEL=info
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## 核心功能使用
|
|
95
|
+
|
|
96
|
+
### 基础服务类
|
|
97
|
+
|
|
98
|
+
继承 `BaseService` 获取基础能力:
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { Provide } from '@midwayjs/core';
|
|
102
|
+
import { BaseService } from '@cicctencent/midwayjs-base';
|
|
103
|
+
import { GetUserInfoReq, GetUserInfoRes } from '@fefeding/common/dist/models/user/request';
|
|
104
|
+
|
|
105
|
+
@Provide()
|
|
106
|
+
export class UserService extends BaseService {
|
|
107
|
+
async getUserInfo(userId: number) {
|
|
108
|
+
// 检查是否为管理员
|
|
109
|
+
const isManager = await this.checkManager();
|
|
110
|
+
|
|
111
|
+
// 方式1:使用请求对象
|
|
112
|
+
const req = new GetUserInfoReq();
|
|
113
|
+
req.userId = userId;
|
|
114
|
+
const result = await this.requestBaseApi<GetUserInfoRes>(req);
|
|
115
|
+
|
|
116
|
+
// 方式2:使用 URL 路径
|
|
117
|
+
// const result = await this.requestBaseApi('/api/user/getInfo', {
|
|
118
|
+
// data: { userId }
|
|
119
|
+
// });
|
|
120
|
+
|
|
121
|
+
return result?.data || null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 会话服务类
|
|
127
|
+
|
|
128
|
+
继承 `ISessionService` 实现会话管理:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import { Provide, Scope, ScopeEnum, Config, Inject } from '@midwayjs/core';
|
|
132
|
+
import { ISessionService, TencentService } from '@cicctencent/midwayjs-base';
|
|
133
|
+
import { Session, GetLoginSessionReq } from '@fefeding/common/dist/models/account/session';
|
|
134
|
+
|
|
135
|
+
@Provide('session:service')
|
|
136
|
+
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
|
137
|
+
export class SessionService extends ISessionService {
|
|
138
|
+
@Config('loginOption')
|
|
139
|
+
loginOption: any;
|
|
140
|
+
|
|
141
|
+
@Inject()
|
|
142
|
+
tencentService: TencentService;
|
|
143
|
+
|
|
144
|
+
async getLoginSession(id: string): Promise<Session> {
|
|
145
|
+
const req = new GetLoginSessionReq();
|
|
146
|
+
req.id = id;
|
|
147
|
+
const res = await this.requestBaseApi(req);
|
|
148
|
+
return res?.data || null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async logout(id: string): Promise<any> {
|
|
152
|
+
// 实现登出逻辑
|
|
153
|
+
this.ctx.currentSession = null;
|
|
154
|
+
return { success: true };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async loginByCode(code: string): Promise<Session> {
|
|
158
|
+
const res = await this.requestBaseApi('/api/session/loginByAuthCode', {
|
|
159
|
+
data: { code }
|
|
160
|
+
});
|
|
161
|
+
return res?.data || null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### 控制器基类
|
|
167
|
+
|
|
168
|
+
继承 `BaseController`:
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
import { Controller, Get } from '@midwayjs/core';
|
|
172
|
+
import { BaseController, CheckLogin } from '@cicctencent/midwayjs-base';
|
|
173
|
+
|
|
174
|
+
@Controller('/api/user')
|
|
175
|
+
export class UserController extends BaseController {
|
|
176
|
+
|
|
177
|
+
@Get('/info')
|
|
178
|
+
@CheckLogin() // 需要登录态
|
|
179
|
+
async getUserInfo() {
|
|
180
|
+
// 获取当前会话信息
|
|
181
|
+
const session = this.ctx.currentSession;
|
|
182
|
+
|
|
183
|
+
return this.success({
|
|
184
|
+
userId: session.userId,
|
|
185
|
+
account: session.account
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### 腾讯云 COS 服务
|
|
192
|
+
|
|
193
|
+
使用 `TencentService` 进行文件操作:
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
import { Provide, Inject } from '@midwayjs/core';
|
|
197
|
+
import { TencentService } from '@cicctencent/midwayjs-base';
|
|
198
|
+
|
|
199
|
+
@Provide()
|
|
200
|
+
export class FileService {
|
|
201
|
+
|
|
202
|
+
@Inject()
|
|
203
|
+
tencentService: TencentService;
|
|
204
|
+
|
|
205
|
+
async uploadFile(filePath: string, key: string) {
|
|
206
|
+
// 上传文件到 COS
|
|
207
|
+
const result = await this.tencentService.uploadCosFile(key, filePath);
|
|
208
|
+
|
|
209
|
+
// 获取文件访问 URL
|
|
210
|
+
const fileUrl = await this.tencentService.getCosFileUrl(key);
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
...result,
|
|
214
|
+
url: fileUrl
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### 工具函数
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
import { utils, jwt } from '@cicctencent/midwayjs-base';
|
|
224
|
+
|
|
225
|
+
// 生成 JWT Token
|
|
226
|
+
const token = jwt.encodeJWT({ userId: 123 }, 'secret-key');
|
|
227
|
+
|
|
228
|
+
// 解码 JWT Token
|
|
229
|
+
const payload = jwt.decodeJWT(token, 'secret-key');
|
|
230
|
+
|
|
231
|
+
// 常用工具函数
|
|
232
|
+
const isEmail = utils.isEmail('test@example.com');
|
|
233
|
+
const timestamp = utils.getTimestamp();
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## 配置说明
|
|
237
|
+
|
|
238
|
+
### 主要配置项
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
// config/config.default.ts
|
|
242
|
+
export default {
|
|
243
|
+
// API 配置
|
|
244
|
+
apiOption: {
|
|
245
|
+
key: 'your-api-key',
|
|
246
|
+
reg: /^\/([^/]+\/)?api\//i,
|
|
247
|
+
ignore: ['/']
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
// IP 白名单
|
|
251
|
+
ipOption: {
|
|
252
|
+
whiteList: ['127.0.0.1', '::1']
|
|
253
|
+
},
|
|
254
|
+
|
|
255
|
+
// 会话配置
|
|
256
|
+
session: {
|
|
257
|
+
timeout: 1200000,
|
|
258
|
+
secretKey: 'your-secret-key'
|
|
259
|
+
},
|
|
260
|
+
|
|
261
|
+
// 认证配置
|
|
262
|
+
auth: {
|
|
263
|
+
ignores: ['/api/test/']
|
|
264
|
+
},
|
|
265
|
+
|
|
266
|
+
// 基础服务配置
|
|
267
|
+
baseService: {
|
|
268
|
+
manager: ['admin'],
|
|
269
|
+
appId: 1001,
|
|
270
|
+
url: 'https://base-service.example.com'
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## 中间件说明
|
|
276
|
+
|
|
277
|
+
### 内置中间件
|
|
278
|
+
|
|
279
|
+
1. **RequestInitMiddleware**: 请求初始化,设置请求 ID 等
|
|
280
|
+
2. **DetectMiddleware**: 请求检测,获取客户端信息
|
|
281
|
+
3. **ApiResultFormatterMiddleware**: 统一 API 响应格式
|
|
282
|
+
|
|
283
|
+
### 守卫器
|
|
284
|
+
|
|
285
|
+
1. **ApiGuard**: API 接口守卫,验证 API Token
|
|
286
|
+
2. **AuthGuard**: 认证守卫,验证登录态
|
|
287
|
+
|
|
288
|
+
## 开发指南
|
|
289
|
+
|
|
290
|
+
### 自定义会话服务
|
|
291
|
+
|
|
292
|
+
实现 `ISessionService` 接口来自定义会话管理:
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
import { Provide } from '@midwayjs/core';
|
|
296
|
+
import { ISessionService } from '@cicctencent/midwayjs-base';
|
|
297
|
+
|
|
298
|
+
@Provide()
|
|
299
|
+
export class CustomSessionService implements ISessionService {
|
|
300
|
+
async getLoginSession(token: string) {
|
|
301
|
+
// 自定义会话获取逻辑
|
|
302
|
+
return session;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async loginByCode(authCode: string) {
|
|
306
|
+
// 自定义登录逻辑
|
|
307
|
+
return session;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### 异常处理
|
|
313
|
+
|
|
314
|
+
组件内置了统一的异常过滤器,支持自定义错误处理。
|
|
315
|
+
|
|
316
|
+
## 部署说明
|
|
317
|
+
|
|
318
|
+
### 构建
|
|
319
|
+
|
|
320
|
+
```bash
|
|
321
|
+
npm run build
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### 测试
|
|
325
|
+
|
|
326
|
+
```bash
|
|
327
|
+
npm test
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### 代码检查
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
npm run lint
|
|
334
|
+
npm run lint:fix
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
## 版本信息
|
|
338
|
+
|
|
339
|
+
当前版本: `1.0.35`
|
|
340
|
+
|
|
341
|
+
## 技术支持
|
|
342
|
+
|
|
343
|
+
如有问题或建议,请联系开发团队。
|
|
344
|
+
|
|
345
|
+
## 许可证
|
|
346
|
+
|
|
347
|
+
MIT License
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { MidwayConfig
|
|
2
|
-
declare const _default: (appInfo:
|
|
1
|
+
import type { MidwayConfig } from '@midwayjs/core';
|
|
2
|
+
declare const _default: (appInfo: any) => MidwayConfig;
|
|
3
3
|
export default _default;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
exports.default = (appInfo) => {
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
export default (appInfo) => {
|
|
6
4
|
appInfo.appId = Number(process.env.APP_ID) || 0;
|
|
7
5
|
const appRoot = appInfo.appDir || appInfo.root;
|
|
8
6
|
appInfo.dist = path.join(appRoot, 'dist');
|
|
@@ -10,21 +8,16 @@ exports.default = (appInfo) => {
|
|
|
10
8
|
appInfo.webPublic = path.join(appInfo.webDist, 'public');
|
|
11
9
|
if (!fs.existsSync(appInfo.webPublic)) {
|
|
12
10
|
fs.mkdirSync(appInfo.webPublic, {
|
|
13
|
-
recursive: true
|
|
11
|
+
recursive: true,
|
|
14
12
|
});
|
|
15
13
|
}
|
|
16
14
|
const config = {
|
|
17
|
-
// use for cookie sign key, should change to your own and keep security
|
|
18
15
|
keys: appInfo.name + '_1641910879296_0612',
|
|
19
16
|
cookies: {
|
|
20
|
-
|
|
21
|
-
secret: '', // 如果为空字符串,则关闭加密,但仍然可以解密已加密的cookies
|
|
22
|
-
// ...
|
|
17
|
+
secret: '',
|
|
23
18
|
},
|
|
24
19
|
view: {
|
|
25
|
-
//默认view目录
|
|
26
20
|
defaultViewEngine: 'nunjucks',
|
|
27
|
-
//默认view目录,本地开发目录必须在web下的,正式环境则是根目录下的view,因为web目录会被删
|
|
28
21
|
rootDir: {
|
|
29
22
|
default: path.join(appInfo.webDist, 'view/'),
|
|
30
23
|
},
|
|
@@ -32,36 +25,36 @@ exports.default = (appInfo) => {
|
|
|
32
25
|
'.html': 'nunjucks',
|
|
33
26
|
},
|
|
34
27
|
},
|
|
35
|
-
// 上传配置
|
|
36
28
|
upload: {
|
|
37
|
-
// 文件模式
|
|
38
29
|
mode: 'file',
|
|
39
|
-
// 上传目录
|
|
40
30
|
fileSize: '10mb',
|
|
41
|
-
whitelist: [
|
|
31
|
+
whitelist: [
|
|
32
|
+
'.jpg',
|
|
33
|
+
'.jpeg',
|
|
34
|
+
'.png',
|
|
35
|
+
'.gif',
|
|
36
|
+
'.webp',
|
|
37
|
+
'.pdf',
|
|
38
|
+
'.doc',
|
|
39
|
+
'.docx',
|
|
40
|
+
'.xls',
|
|
41
|
+
'.xlsx',
|
|
42
|
+
'.ppt',
|
|
43
|
+
'.pptx',
|
|
44
|
+
],
|
|
42
45
|
},
|
|
43
|
-
// 静态文件服务
|
|
44
46
|
staticFile: {
|
|
45
47
|
dirs: {
|
|
46
48
|
default: {
|
|
47
|
-
// 默认public目录
|
|
48
49
|
dir: appInfo.webPublic,
|
|
49
50
|
},
|
|
50
51
|
},
|
|
51
52
|
},
|
|
52
|
-
/**
|
|
53
|
-
* api相关配置
|
|
54
|
-
*/
|
|
55
53
|
apiOption: {
|
|
56
|
-
// 接口请求校验key
|
|
57
54
|
key: process.env.API_KEY || '2024@fefeding#',
|
|
58
55
|
reg: /^\/([^/]+\/)?api\//i,
|
|
59
|
-
ignore: [
|
|
60
|
-
'/',
|
|
61
|
-
/^\/([^/]+\/)?api\/cos\/get/i
|
|
62
|
-
]
|
|
56
|
+
ignore: ['/', /^\/([^/]+\/)?api\/cos\/get/i],
|
|
63
57
|
},
|
|
64
|
-
// ip白名单
|
|
65
58
|
ipOption: {
|
|
66
59
|
whiteList: [
|
|
67
60
|
'127.0.0.1',
|
|
@@ -69,52 +62,36 @@ exports.default = (appInfo) => {
|
|
|
69
62
|
'0.0.0.0',
|
|
70
63
|
'::',
|
|
71
64
|
'localhost',
|
|
72
|
-
...(process.env.IP_WHITE_LIST?.split(',') || [])
|
|
65
|
+
...(process.env.IP_WHITE_LIST?.split(',') || []),
|
|
73
66
|
],
|
|
74
67
|
},
|
|
75
|
-
// 查看系统信息
|
|
76
68
|
info: {
|
|
77
69
|
infoPath: '/_sys_info',
|
|
78
70
|
},
|
|
79
71
|
axios: {
|
|
80
|
-
default: {
|
|
81
|
-
// 所有实例复用的配置
|
|
82
|
-
},
|
|
72
|
+
default: {},
|
|
83
73
|
clients: {
|
|
84
|
-
// 默认实例的配置
|
|
85
74
|
default: {
|
|
86
|
-
// `headers` are custom headers to be sent
|
|
87
75
|
headers: {
|
|
88
76
|
'X-Requested-With': 'XMLHttpRequest',
|
|
89
77
|
},
|
|
90
|
-
timeout: 1000,
|
|
91
|
-
|
|
92
|
-
// should be made using credentials
|
|
93
|
-
withCredentials: false, // default
|
|
78
|
+
timeout: 1000,
|
|
79
|
+
withCredentials: false,
|
|
94
80
|
},
|
|
95
81
|
},
|
|
96
82
|
},
|
|
97
|
-
// 基础服务
|
|
98
83
|
baseService: {
|
|
99
|
-
manager: ['admin'],
|
|
84
|
+
manager: ['admin'],
|
|
100
85
|
appId: appInfo.appId,
|
|
101
|
-
url: process.env.BASE_SERVER_URL || ''
|
|
86
|
+
url: process.env.BASE_SERVER_URL || '',
|
|
102
87
|
},
|
|
103
88
|
session: {
|
|
104
|
-
// session 过期设置
|
|
105
89
|
timeout: Number(process.env.SESSION_TIMEOUT) || 20 * 60 * 1000,
|
|
106
90
|
secretKey: 'fjjiowhb@#$^111)*&',
|
|
107
|
-
//serviceKey: 'session:service',
|
|
108
91
|
},
|
|
109
|
-
// 登陆态校验配置
|
|
110
92
|
auth: {
|
|
111
|
-
|
|
112
|
-
ignores: [
|
|
113
|
-
/\/api\/test\//i,
|
|
114
|
-
"/api/test/action"
|
|
115
|
-
]
|
|
93
|
+
ignores: [/\/api\/test\//i, '/api/test/action'],
|
|
116
94
|
},
|
|
117
|
-
// 登陆相关配置
|
|
118
95
|
sso: {
|
|
119
96
|
baseUrl: process.env.SSO_URL || '',
|
|
120
97
|
appId: appInfo.appId,
|
|
@@ -135,26 +112,25 @@ exports.default = (appInfo) => {
|
|
|
135
112
|
default: {
|
|
136
113
|
store: 'memory',
|
|
137
114
|
options: {
|
|
138
|
-
max: 10000,
|
|
139
|
-
ttl: 600000,
|
|
115
|
+
max: 10000,
|
|
116
|
+
ttl: 600000,
|
|
140
117
|
},
|
|
141
118
|
},
|
|
142
119
|
},
|
|
143
120
|
session: {
|
|
144
121
|
store: 'memory',
|
|
145
122
|
options: {
|
|
146
|
-
max: 10000,
|
|
147
|
-
ttl: 600000,
|
|
123
|
+
max: 10000,
|
|
124
|
+
ttl: 600000,
|
|
148
125
|
},
|
|
149
126
|
},
|
|
150
127
|
},
|
|
151
128
|
logger: {
|
|
152
|
-
// 日志配置
|
|
153
129
|
level: process.env.LOG_LEVEL || 'info',
|
|
154
130
|
consoleLevel: process.env.LOG_LEVEL || 'info',
|
|
155
131
|
remoteUrl: process.env.REMOTE_LOGGER_URL || '',
|
|
156
|
-
}
|
|
132
|
+
},
|
|
157
133
|
};
|
|
158
134
|
return config;
|
|
159
135
|
};
|
|
160
|
-
//# sourceMappingURL=
|
|
136
|
+
//# sourceMappingURL=config.default.js.map
|
package/dist/config/env.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const path = require("path");
|
|
6
|
-
const fs = require("fs");
|
|
7
|
-
function loadEnv(envPath) {
|
|
1
|
+
import * as dotenv from 'dotenv';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
export function loadEnv(envPath) {
|
|
8
5
|
envPath = envPath || path.join(process.cwd(), '.env');
|
|
9
6
|
console.log('env path', envPath);
|
|
10
7
|
if (fs.existsSync(envPath)) {
|
|
11
8
|
const env = dotenv.config({
|
|
12
9
|
path: envPath,
|
|
13
|
-
encoding: 'utf-8'
|
|
10
|
+
encoding: 'utf-8',
|
|
14
11
|
});
|
|
15
12
|
console.log(env);
|
|
16
13
|
}
|
|
17
14
|
return process.env;
|
|
18
15
|
}
|
|
19
|
-
//# sourceMappingURL=
|
|
16
|
+
//# sourceMappingURL=env.js.map
|
package/dist/configuration.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,55 +7,43 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const DefaultConfig = require("./config/config.default");
|
|
27
|
-
const api_1 = require("./guard/api");
|
|
28
|
-
const auth_1 = require("./guard/auth");
|
|
29
|
-
// load .env file in process.cwd
|
|
30
|
-
const env_1 = require("./config/env");
|
|
31
|
-
(0, env_1.loadEnv)();
|
|
10
|
+
import { Configuration, App } from '@midwayjs/core';
|
|
11
|
+
import * as koa from '@midwayjs/koa';
|
|
12
|
+
import * as info from '@midwayjs/info';
|
|
13
|
+
import * as axios from '@midwayjs/axios';
|
|
14
|
+
import { ApiResultFormatterMiddleware } from './middleware/apiResultFormatter';
|
|
15
|
+
import { RequestInitMiddleware } from './middleware/requestInit';
|
|
16
|
+
import { DetectMiddleware } from './middleware/detect.middleware';
|
|
17
|
+
import * as view from '@midwayjs/view-nunjucks';
|
|
18
|
+
import * as staticFile from '@midwayjs/static-file';
|
|
19
|
+
import * as cacheManager from '@midwayjs/cache-manager';
|
|
20
|
+
import * as DefaultConfig from './config/config.default';
|
|
21
|
+
import { ApiGuard } from './guard/api';
|
|
22
|
+
import { AuthGuard } from './guard/auth';
|
|
23
|
+
import { loadEnv } from './config/env';
|
|
24
|
+
loadEnv();
|
|
32
25
|
let BaseConfiguration = class BaseConfiguration {
|
|
33
|
-
app;
|
|
34
26
|
async onReady() {
|
|
35
27
|
if (process.env.FEFE_MIDWAYJS_BASE_READY === 'true') {
|
|
36
28
|
return;
|
|
37
29
|
}
|
|
38
|
-
process.env.SERVICE_NAME =
|
|
39
|
-
|
|
40
|
-
this.app.useGuard([
|
|
41
|
-
api_1.ApiGuard,
|
|
42
|
-
auth_1.AuthGuard
|
|
43
|
-
]);
|
|
44
|
-
// add middleware
|
|
30
|
+
process.env.SERVICE_NAME =
|
|
31
|
+
process.env.SERVICE_NAME || this.app.getProjectName();
|
|
32
|
+
this.app.useGuard([ApiGuard, AuthGuard]);
|
|
45
33
|
this.app.useMiddleware([
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
34
|
+
RequestInitMiddleware,
|
|
35
|
+
DetectMiddleware,
|
|
36
|
+
ApiResultFormatterMiddleware,
|
|
49
37
|
]);
|
|
50
38
|
process.env.FEFE_MIDWAYJS_BASE_READY = 'true';
|
|
51
39
|
}
|
|
52
40
|
};
|
|
53
|
-
exports.BaseConfiguration = BaseConfiguration;
|
|
54
41
|
__decorate([
|
|
55
|
-
|
|
42
|
+
App(),
|
|
56
43
|
__metadata("design:type", Object)
|
|
57
44
|
], BaseConfiguration.prototype, "app", void 0);
|
|
58
|
-
|
|
59
|
-
|
|
45
|
+
BaseConfiguration = __decorate([
|
|
46
|
+
Configuration({
|
|
60
47
|
namespace: 'MidwayjsBase',
|
|
61
48
|
imports: [
|
|
62
49
|
koa,
|
|
@@ -76,4 +63,5 @@ exports.BaseConfiguration = BaseConfiguration = __decorate([
|
|
|
76
63
|
],
|
|
77
64
|
})
|
|
78
65
|
], BaseConfiguration);
|
|
79
|
-
|
|
66
|
+
export { BaseConfiguration };
|
|
67
|
+
//# sourceMappingURL=configuration.js.map
|