init
This commit is contained in:
129
config/framework.config.js
Normal file
129
config/framework.config.js
Normal file
@@ -0,0 +1,129 @@
|
||||
/**
|
||||
* Framework 配置文件
|
||||
* 基于 node-core-framework 的配置
|
||||
*/
|
||||
|
||||
const path = require("path");
|
||||
const baseConfig = require("./config.js");
|
||||
const customSchemas = require("./custom.schemas.js");
|
||||
|
||||
module.exports = {
|
||||
// ===== 必需配置 =====
|
||||
env: process.env.NODE_ENV || 'development',
|
||||
"project_key": "fullstack_template",
|
||||
// 数据库配置(必需)
|
||||
db: {
|
||||
username: baseConfig.db.username,
|
||||
password: baseConfig.db.password,
|
||||
database: baseConfig.db.database,
|
||||
host: baseConfig.db.host,
|
||||
port: baseConfig.db.port || 3306,
|
||||
dialect: baseConfig.db.dialect || 'mysql',
|
||||
timezone: '+08:00',
|
||||
// 远程 MySQL 常见:wait_timeout / 网络设备掐断空闲连接 → 池中连接已死仍被复用 → SequelizeConnectionError
|
||||
dialectOptions: {
|
||||
connectTimeout: 60000,
|
||||
// mysql2@2+ 有效;旧版会忽略未知项
|
||||
enableKeepAlive: true,
|
||||
keepAliveInitialDelay: 10000,
|
||||
},
|
||||
pool: {
|
||||
max: 50,
|
||||
// min>0 会长期占着连接,服务端先断开后易 “Connection lost”;开发/低频接口建议 0
|
||||
min: 0,
|
||||
acquire: 60000,
|
||||
// 空闲超过 idle(ms) 释放回池,应小于 MySQL wait_timeout(常见 600~28800s)
|
||||
idle: 10000,
|
||||
// 定期清理池中空闲连接,降低复用到已被服务端关闭的 TCP
|
||||
evict: 15000,
|
||||
},
|
||||
slowSQLThreshold: 1000,
|
||||
logging: (() => {
|
||||
// 启用SQL监控
|
||||
|
||||
return (sql, timing) => {
|
||||
// 调用监控函数
|
||||
|
||||
// 开发环境仍然输出日志
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
console.log(`[SQL] ${timing}ms - ${typeof sql === 'string' ? sql : (sql.sql || JSON.stringify(sql))}`);
|
||||
}
|
||||
};
|
||||
})()
|
||||
},
|
||||
|
||||
// API 路径配置(必需):模板仅保留管理端业务控制器目录
|
||||
apiPaths: [
|
||||
{
|
||||
path: "./api/controller_admin",
|
||||
prefix: "/admin_api",
|
||||
authType: "admin",
|
||||
},
|
||||
],
|
||||
|
||||
"fileConifg": {
|
||||
"vue": {
|
||||
"api": "../../admin/src/api/",
|
||||
"view": "../../admin/src/view/"
|
||||
},
|
||||
"node": {
|
||||
"controller": "../controller_admin/",
|
||||
"model": "../model/"
|
||||
}
|
||||
},
|
||||
|
||||
// API文档配置
|
||||
swagger: {
|
||||
title: "Fullstack Template API",
|
||||
version: "1.0.0",
|
||||
description: "admin-framework + node-core-framework 模板项目 API",
|
||||
contact: {
|
||||
name: '开发团队',
|
||||
email: 'dev@example.com'
|
||||
}
|
||||
},
|
||||
|
||||
// ===== 建议配置 =====
|
||||
|
||||
// 基础 URL(根据环境区分)
|
||||
baseUrl: (() => {
|
||||
const env = process.env.NODE_ENV || 'production';
|
||||
|
||||
|
||||
|
||||
switch (env) {
|
||||
case "production":
|
||||
return "http://localhost:9098";
|
||||
case "development":
|
||||
default:
|
||||
return "http://localhost:9098";
|
||||
}
|
||||
})(),
|
||||
|
||||
// 日志路径
|
||||
logPath: './logs',
|
||||
|
||||
// 白名单 URL(不需要认证的接口)
|
||||
allowUrls: baseConfig.allowUrls,
|
||||
|
||||
// 授权文件路径(可选,如果不需要授权验证可以设置为 null)
|
||||
// node-core-framework 读取顶层字段 licensePath
|
||||
licensePath: path.join(__dirname, "..", "_license", "license.lic"),
|
||||
|
||||
|
||||
// Redis 配置
|
||||
redis: baseConfig.redis || null,
|
||||
|
||||
// 模型路径
|
||||
modelPaths: './api/model',
|
||||
|
||||
// ===== 业务配置(从原 config.js 继承)=====
|
||||
|
||||
// 端口配置
|
||||
port: baseConfig.port,
|
||||
|
||||
|
||||
// 自定义 Swagger Schemas
|
||||
customSchemas: customSchemas
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user