mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added a unified CLI entry point for server operations and introduced a new CLI executable alias. - Centralized and simplified server startup, allowing selection between CLI and server modes. - Added static migration module aggregation for easier migration management. - **Bug Fixes** - Improved platform-specific native module loading for better compatibility and reliability. - **Refactor** - Streamlined server build, startup, and artifact management processes. - Reorganized and simplified workflow and configuration files for backend services. - Transitioned export styles and import mechanisms for native modules to enhance maintainability. - **Chores** - Removed unused dependencies and configuration files. - Updated test cases to reflect refined server flavor logic. - Adjusted package and build configurations for consistency and clarity. - **Revert** - Removed legacy scripts and loaders no longer needed after refactor. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
71 lines
2.0 KiB
TypeScript
71 lines
2.0 KiB
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import type { NestExpressApplication } from '@nestjs/platform-express';
|
|
import cookieParser from 'cookie-parser';
|
|
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';
|
|
|
|
import {
|
|
AFFiNELogger,
|
|
CacheInterceptor,
|
|
CloudThrottlerGuard,
|
|
Config,
|
|
GlobalExceptionFilter,
|
|
URLHelper,
|
|
} from './base';
|
|
import { SocketIoAdapter } from './base/websocket';
|
|
import { AuthGuard } from './core/auth';
|
|
import { serverTimingAndCache } from './middleware/timing';
|
|
|
|
const OneMB = 1024 * 1024;
|
|
|
|
export async function run() {
|
|
const { AppModule } = await import('./app.module');
|
|
|
|
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
|
|
cors: true,
|
|
rawBody: true,
|
|
bodyParser: true,
|
|
bufferLogs: true,
|
|
});
|
|
|
|
app.useBodyParser('raw', { limit: 100 * OneMB });
|
|
|
|
const logger = app.get(AFFiNELogger);
|
|
app.useLogger(logger);
|
|
const config = app.get(Config);
|
|
|
|
if (config.server.path) {
|
|
app.setGlobalPrefix(config.server.path);
|
|
}
|
|
|
|
app.use(serverTimingAndCache);
|
|
|
|
app.use(
|
|
graphqlUploadExpress({
|
|
maxFileSize: 100 * OneMB,
|
|
maxFiles: 32,
|
|
})
|
|
);
|
|
|
|
app.useGlobalGuards(app.get(AuthGuard), app.get(CloudThrottlerGuard));
|
|
app.useGlobalInterceptors(app.get(CacheInterceptor));
|
|
app.useGlobalFilters(new GlobalExceptionFilter(app.getHttpAdapter()));
|
|
app.use(cookieParser());
|
|
// only enable shutdown hooks in production
|
|
// https://docs.nestjs.com/fundamentals/lifecycle-events#application-shutdown
|
|
if (env.prod) {
|
|
app.enableShutdownHooks();
|
|
}
|
|
|
|
const adapter = new SocketIoAdapter(app);
|
|
app.useWebSocketAdapter(adapter);
|
|
|
|
const url = app.get(URLHelper);
|
|
const listeningHost = '0.0.0.0';
|
|
|
|
await app.listen(config.server.port, listeningHost);
|
|
|
|
logger.log(`AFFiNE Server is running in [${env.DEPLOYMENT_TYPE}] mode`);
|
|
logger.log(`Listening on http://${listeningHost}:${config.server.port}`);
|
|
logger.log(`And the public server should be recognized as ${url.home}`);
|
|
}
|