This commit is contained in:
张成
2026-04-29 13:34:39 +08:00
commit dee3a336ce
89 changed files with 33683 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
/**
* 本地开发配置(请按实际环境修改数据库等)
*/
module.exports = {
db: {
username: "root",
password: "your_password",
database: "fullstack_template",
host: "127.0.0.1",
port: 3306,
dialect: "mysql",
},
aliyun: {
accessKeyId: "",
accessKeySecret: "",
ossUrl: "",
bucket: "",
},
redis: null,
};

41
config/config.js Normal file
View File

@@ -0,0 +1,41 @@
// 共享配置;环境相关变量放在 config.development.js / config.production.js
const env = process.env.NODE_ENV || "development";
let env_config = {};
try {
if (env === "production") {
env_config = require("./config.production.js");
} else {
env_config = require("./config.development.js");
}
} catch (error) {
console.warn(`Warning: failed to load ${env} config, using defaults.`);
}
const base_config = {
port: {
node: 9098,
web: 9090,
},
allowUrls: [
"/admin_api/sys_user/login",
"/admin_api/sys_user/authorityMenus",
"/admin_api/sys_user/register",
"/file/",
"/sys_file/",
"/api/docs",
"/api/swagger.json",
],
};
module.exports = {
...base_config,
...env_config,
wechat: {
...(base_config.wechat || {}),
...(env_config.wechat || {}),
},
};
console.log(`Config env: ${env}`);

View File

@@ -0,0 +1,21 @@
/**
* 生产环境配置(部署时填写真实连接信息)
*/
module.exports = {
db: {
username: "root",
password: "your_password",
database: "fullstack_template",
host: "127.0.0.1",
port: 3306,
dialect: "mysql",
},
aliyun: {
accessKeyId: "",
accessKeySecret: "",
ossUrl: "",
bucket: "",
},
redis: null,
};

11
config/custom.schemas.js Normal file
View File

@@ -0,0 +1,11 @@
/**
* 自定义 Swagger Schemas
* 用于定义复合响应结构和业务特定的 Schema
*/
module.exports = {
};

129
config/framework.config.js Normal file
View 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常见 60028800s
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
};

View File

@@ -0,0 +1,5 @@
/**
* 业务模型关联(模板项目无额外 Sequelize 关联,在此按需补充)
* @param {Object} models - 所有模型对象
*/
module.exports = () => {};