重构 server/app.tsx - 仅保留应用初始化和服务启动逻辑
This commit is contained in:
50
server/router.ts
Normal file
50
server/router.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/** @jsxImportSource https://esm.d8d.fun/hono@4.7.4/jsx */
|
||||
import { Hono } from 'hono'
|
||||
import { corsMiddleware, withAuth, setEnvVariables } from './middlewares.ts'
|
||||
import type { APIClient } from '@d8d-appcontainer/api'
|
||||
|
||||
// 导入路由模块
|
||||
import { createAuthRoutes } from "./routes_auth.ts"
|
||||
import { createUserRoutes } from "./routes_users.ts"
|
||||
import { createKnowInfoRoutes } from "./routes_know_info.ts"
|
||||
import { createFileUploadRoutes } from "./routes_file_upload.ts"
|
||||
import { createFileCategoryRoutes } from "./routes_file_category.ts"
|
||||
import { createThemeRoutes } from "./routes_theme.ts"
|
||||
import { createChartRoutes } from "./routes_charts.ts"
|
||||
import { createMapRoutes } from "./routes_maps.ts"
|
||||
import { createSystemSettingsRoutes } from "./routes_system_settings.ts"
|
||||
import { createMessagesRoutes } from "./routes_messages.ts"
|
||||
import { createMigrationsRoutes } from "./routes_migrations.ts"
|
||||
import { createHomeRoutes } from "./routes_home.ts"
|
||||
|
||||
export function createRouter(apiClient: APIClient, moduleDir: string) {
|
||||
const router = new Hono()
|
||||
|
||||
// 添加CORS中间件
|
||||
router.use('/*', corsMiddleware)
|
||||
|
||||
// 创建API路由
|
||||
const api = new Hono()
|
||||
|
||||
// 设置环境变量
|
||||
api.use('*', setEnvVariables(apiClient, moduleDir))
|
||||
|
||||
// 注册所有路由
|
||||
api.route('/auth', createAuthRoutes(withAuth))
|
||||
api.route('/users', createUserRoutes(withAuth))
|
||||
api.route('/know-infos', createKnowInfoRoutes(withAuth))
|
||||
api.route('/upload', createFileUploadRoutes(withAuth))
|
||||
api.route('/file-categories', createFileCategoryRoutes(withAuth))
|
||||
api.route('/theme', createThemeRoutes(withAuth))
|
||||
api.route('/charts', createChartRoutes(withAuth))
|
||||
api.route('/map', createMapRoutes(withAuth))
|
||||
api.route('/settings', createSystemSettingsRoutes(withAuth))
|
||||
api.route('/messages', createMessagesRoutes(withAuth))
|
||||
api.route('/migrations', createMigrationsRoutes(withAuth))
|
||||
api.route('/home', createHomeRoutes(withAuth))
|
||||
|
||||
// 注册API路由到主路由器
|
||||
router.route('/api', api)
|
||||
|
||||
return router
|
||||
}
|
||||
Reference in New Issue
Block a user