mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-11-17 16:13:36 +08:00
Enforce live session grants for runtime routes and support profile and credential updates in both the backend and demo modes. Add the account settings workspace and document fullstack setup and PC acceptance.
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import 'reflect-metadata'
|
|
import { Module } from '@nestjs/common'
|
|
import type { DynamicModule } from '@nestjs/common'
|
|
import { NestFactory } from '@nestjs/core'
|
|
import type { NestExpressApplication } from '@nestjs/platform-express'
|
|
import { ApiExceptionFilter, EnvelopeInterceptor } from './http'
|
|
import { DatabaseModule, DatabaseService } from './infrastructure/database'
|
|
import { AuthModule } from './modules/auth/auth.module'
|
|
import { DemoController } from './modules/demo/demo.controller'
|
|
import { RoutesModule } from './modules/routes/routes.module'
|
|
import { UsersModule } from './modules/users/users.module'
|
|
import { loadServerConfig, PlatformRuntime } from './platform/index'
|
|
import type { LogSink, ServerConfig } from './platform/index'
|
|
import { PlatformLifecycle } from './platform/lifecycle'
|
|
|
|
@Module({})
|
|
export class AppModule {
|
|
static register(config: ServerConfig): DynamicModule {
|
|
return {
|
|
module: AppModule,
|
|
imports: [
|
|
DatabaseModule.register(config),
|
|
AuthModule,
|
|
UsersModule,
|
|
RoutesModule,
|
|
],
|
|
controllers: config.demoEnabled ? [DemoController] : [],
|
|
providers: [PlatformLifecycle],
|
|
}
|
|
}
|
|
}
|
|
|
|
export async function createApp(
|
|
config: ServerConfig = loadServerConfig(),
|
|
options: { logSink?: LogSink } = {},
|
|
) {
|
|
const app = await NestFactory.create<NestExpressApplication>(
|
|
AppModule.register(config),
|
|
{
|
|
logger: false,
|
|
bodyParser: false,
|
|
abortOnError: false,
|
|
},
|
|
)
|
|
|
|
try {
|
|
const database = app.get(DatabaseService)
|
|
const runtime = await PlatformRuntime.create(config, {
|
|
checkDatabase: () => database.assertInitialized(),
|
|
logSink: options.logSink,
|
|
})
|
|
|
|
app.get(PlatformLifecycle).runtime = runtime
|
|
runtime.install(app)
|
|
app.setGlobalPrefix('api')
|
|
app.useGlobalInterceptors(new EnvelopeInterceptor())
|
|
app.useGlobalFilters(new ApiExceptionFilter())
|
|
await app.init()
|
|
|
|
return app
|
|
} catch (error) {
|
|
await app.close()
|
|
throw error
|
|
}
|
|
}
|