mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-12 23:56:36 +08:00
e516e0db23
- [x] separates modules into `fundamental`, `core`, `plugins`
- [x] optional modules with `@OptionalModule` decorator to install modules with requirements met(`requires`, `if`)
- [x] `module.contributesTo` defines optional features that will be enabled if module registered
- [x] `AFFiNE.plugins.use('payment', {})` to enable a optional/plugin module
- [x] `PaymentModule` is the first plugin module
- [x] GraphQLSchema will not be generated for non-included modules
- [x] Frontend can use `ServerConfigType` query to detect which features are enabled
- [x] override existing provider globally
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { Type } from '@nestjs/common';
|
|
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 { SocketIoAdapter } from './fundamentals';
|
|
import { SocketIoAdapterImpl } from './fundamentals/websocket';
|
|
import { ExceptionLogger } from './middleware/exception-logger';
|
|
import { serverTimingAndCache } from './middleware/timing';
|
|
|
|
export async function createApp() {
|
|
const { AppModule } = await import('./app.module');
|
|
|
|
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
|
|
cors: true,
|
|
rawBody: true,
|
|
bodyParser: true,
|
|
logger: AFFiNE.affine.stable ? ['log'] : ['verbose'],
|
|
});
|
|
|
|
app.use(serverTimingAndCache);
|
|
|
|
app.use(
|
|
graphqlUploadExpress({
|
|
// TODO: dynamic limit by quota
|
|
maxFileSize: 100 * 1024 * 1024,
|
|
maxFiles: 5,
|
|
})
|
|
);
|
|
|
|
app.useGlobalFilters(new ExceptionLogger());
|
|
app.use(cookieParser());
|
|
|
|
if (AFFiNE.flavor.sync) {
|
|
const SocketIoAdapter = app.get<Type<SocketIoAdapter>>(
|
|
SocketIoAdapterImpl,
|
|
{
|
|
strict: false,
|
|
}
|
|
);
|
|
|
|
const adapter = new SocketIoAdapter(app);
|
|
app.useWebSocketAdapter(adapter);
|
|
}
|
|
|
|
return app;
|
|
}
|