跳转到内容

平台启动

createPlatform() 是 VentoStack 平台层的聚合入口,一次性创建并组装所有业务模块(系统管理、代码生成、监控、通知、国际化、工作流、文件存储、任务调度),避免手动逐个实例化和注册。

import { createPlatform } from "@ventostack/boot";
const platform = await createPlatform({
executor,
readTableSchema,
listTables,
cache,
jwt,
jwtSecret,
passwordHasher,
totpManager,
rbac,
rowFilter,
authSessionManager,
tokenRefreshManager,
sessionManager,
multiDeviceManager,
auditStore,
eventBus,
healthCheck,
scheduler,
});
// 注册所有模块路由
app.use(platform.router);
// 初始化所有模块(加载权限、启动定时任务等)
await platform.init();
参数类型说明
executorSqlExecutor数据库执行器
cacheCache缓存实例
jwtJWTManagerJWT 管理器
jwtSecretstringJWT 签名密钥
passwordHasherPasswordHasher密码哈希器
totpManagerTOTPManagerTOTP 双因素认证
rbacRBACRBAC 权限引擎
rowFilterRowFilter行级过滤器
authSessionManagerAuthSessionManager统一认证会话
tokenRefreshManagerTokenRefreshManagerToken 刷新管理
sessionManagerSessionManagerSession 管理
multiDeviceManagerMultiDeviceManager多设备管理
auditStoreAuditStore审计日志存储
eventBusEventBus事件总线
healthCheckHealthCheck健康检查
schedulerScheduler调度器
参数类型说明
dbDatabase数据库实例,未提供时从 executor 自动创建
storageAdapterStorageAdapterOSS 存储适配器(启用文件存储模块时必填)
notifyChannelsMap<string, NotifyChannel>通知通道(启用通知模块时必填)
jobHandlersJobHandlerMap定时任务处理器(启用调度模块时建议配置)

通过 modules 对象可以按需禁用特定模块(默认全部启用):

const platform = await createPlatform({
// ...依赖配置
modules: {
system: true, // 系统管理(用户、角色、菜单等)
gen: true, // 代码生成
monitor: true, // 系统监控
notification: false, // 禁用通知
i18n: true, // 国际化
workflow: true, // 工作流
oss: true, // 文件存储
scheduler: true, // 任务调度
},
});
字段类型说明
systemSystemModule?系统管理模块实例
genGenModule?代码生成模块实例
monitorMonitorModule?监控模块实例
notificationNotificationModule?通知模块实例
i18nI18nModule?国际化模块实例
workflowWorkflowModule?工作流模块实例
ossOSSModule?文件存储模块实例
schedulerSchedulerModule?调度模块实例
routerRouter聚合所有已启用模块路由的统一路由器
init()() => Promise<void>初始化所有已启用模块
import { createApp, createRouter, cors, requestId, requestLogger, errorHandler } from "@ventostack/core";
import { createPlatform } from "@ventostack/boot";
// 1. 基础设施
const database = createDatabaseConnection();
const cache = await createCacheInstance();
const auth = assembleAuthEngines(cache.redisClient);
// 2. 平台聚合
const platform = await createPlatform({
executor: database.executor,
db: database.db,
readTableSchema,
listTables,
cache: cache.cache,
jwt: auth.jwt,
jwtSecret: auth.jwtSecret,
passwordHasher: auth.passwordHasher,
totpManager: auth.totp,
rbac: auth.rbac,
rowFilter: auth.rowFilter,
authSessionManager: auth.authSessionManager,
tokenRefreshManager: auth.tokenRefresh,
sessionManager: auth.sessionManager,
multiDeviceManager: auth.deviceManager,
auditStore: createAuditLog(),
eventBus: createEventBus(),
healthCheck: createDefaultHealthCheck({ sql: database.executor }),
scheduler: createScheduler(),
storageAdapter: createStorageAdapter(),
});
await platform.init();
// 3. 应用装配
const app = createApp({ port: 9320 });
app.use(requestId());
app.use(cors({ origin: ["http://localhost:3000"] }));
app.use(requestLogger());
// 健康检查(无需认证)
app.use(healthRouter);
// 注意:Admin 生产部署已将 /health、/metrics、/docs 等管理端点移至独立的 ADMIN_PORT(默认 9322)。
// 上方示例展示的是框架层的基本用法,生产部署建议参考 Admin 部署文档。
// 平台路由(自动包含所有模块)
app.use(platform.router);
app.use(errorHandler());
await app.listen();

createPlatform 遵循以下原则:

  • 默认启用:所有模块默认启用,通过 modules 按需关闭
  • 依赖注入:所有基础设施通过参数传入,不自行创建
  • 路由聚合:返回统一 router,内部按模块挂载子路由
  • 延迟初始化init() 单独调用,确保数据库和缓存已就绪