增加socketio 路由 支持

This commit is contained in:
yourname
2025-05-15 08:40:09 +00:00
parent b879ad4f7c
commit dea7ec5316
8 changed files with 350 additions and 58 deletions

View File

@@ -45,11 +45,11 @@ export const withAuth = async (c: HonoContext<{ Variables: Variables }>, next: (
export type WithAuth = typeof withAuth;
// 环境变量设置中间件
export const setEnvVariables = (apiClient: APIClient, moduleDir: string) => {
export const setEnvVariables = (apiClient: APIClient, moduleDir: string, auth: Auth) => {
return async (c: HonoContext<{ Variables: Variables }>, next: () => Promise<void>) => {
c.set('apiClient', apiClient)
c.set('moduleDir', moduleDir)
c.set('auth', await initAuth(apiClient))
c.set('auth', auth)
c.set('systemSettings', await initSystemSettings(apiClient))
await next()
}
@@ -58,37 +58,7 @@ export const setEnvVariables = (apiClient: APIClient, moduleDir: string) => {
// CORS中间件
export const corsMiddleware = cors()
// 初始化Auth实例
const initAuth = async (apiClient: APIClient) => {
try {
log.auth('正在初始化Auth实例')
const auth = new Auth(apiClient as any, {
jwtSecret: Deno.env.get("JWT_SECRET") || 'your-jwt-secret-key',
initialUsers: [],
storagePrefix: '',
userTable: 'users',
fieldNames: {
id: 'id',
username: 'username',
password: 'password',
phone: 'phone',
email: 'email',
is_disabled: 'is_disabled',
is_deleted: 'is_deleted'
},
tokenExpiry: 24 * 60 * 60,
refreshTokenExpiry: 7 * 24 * 60 * 60
})
log.auth('Auth实例初始化完成')
return auth
} catch (error) {
log.auth('Auth初始化失败:', error)
throw error
}
}
// 初始化系统设置
const initSystemSettings = async (apiClient: APIClient) => {