1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
| import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
| import { CoolConfig } from '@cool-midway/core';
| import * as path from 'path';
| import { CoolFileConfig, MODETYPE } from '@cool-midway/file';
|
| export type DefaultConfig = PowerPartial<EggAppConfig>;
|
| export default (appInfo: EggAppInfo) => {
| const config = {} as DefaultConfig;
| // cookie sign key
| config.keys = appInfo.name + 'cool-admin-next';
|
| // 启用中间件 这里需要设置为 [] 否则CoolController设置的中间件也会无效
| config.middleware = [];
|
| // 模板渲染 用法 https://nunjucks.bootcss.com
| config.view = {
| root: [path.join(appInfo.baseDir, 'app/view')].join(','),
| defaultViewEngine: 'nunjucks',
| defaultExtension: '.html',
| mapping: {
| '.html': 'nunjucks',
| },
| };
|
| // 靜態目錄及緩存設置
| config.static = {
| prefix: '',
| dir: path.join(appInfo.baseDir, '..', 'public'),
| dynamic: true,
| preload: false,
| // maxAge: 31536000,
| maxAge: 0,
| buffer: false,
| };
|
| // 修改默认的 favicon.ico serverless 环境下无用
| // config.siteFile = {
| // '/favicon.ico': fs.readFileSync(
| // path.join(appInfo.baseDir, 'app/public/favicon.ico')
| // ),
| // };
|
| // 关闭安全校验
| config.security = {
| csrf: {
| enable: false,
| ignoreJSON: true,
| },
| domainWhiteList: ['http://localhost:9100', 'http://192.168.1.4:9100', 'http://112.74.77.127:9100'],
| };
|
| config.cors = {
| origin: '*', // 匹配规则 域名+端口 *则为全匹配
| allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
| };
|
| // cool-admin特有的配置
| config.cool = {
| // 是否初始化模块数据库
| initDB: true,
| // 全局路由前缀
| router: {
| prefix: '',
| },
| // 单点登录
| sso: false,
|
| // 分页配置
| page: {
| // 分页查询每页条数
| size: 15,
| },
| // 文件上传
| file: {
| // 文件路径前缀 本地上传模式下 有效
| // domain: 'http://127.0.0.1:8001',
| domain: 'http://112.74.77.127:9100/hn',
| },
| } as CoolConfig;
|
| // 文件上传
| config.multipart = {
| fileSize: '100mb',
| mode: 'file',
| whitelist: () => true,
| };
|
| // 将egg日志替换成midway
| config.midwayFeature = {
| replaceEggLogger: true,
| };
|
| return config;
| };
|
|