mirror of
https://github.com/docmost/docmost.git
synced 2025-11-16 00:21:12 +10:00
68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import { AppModule } from './app.module';
|
|
import {
|
|
FastifyAdapter,
|
|
NestFastifyApplication,
|
|
} from '@nestjs/platform-fastify';
|
|
import { NotFoundException, ValidationPipe } from '@nestjs/common';
|
|
import { TransformHttpResponseInterceptor } from './common/interceptors/http-response.interceptor';
|
|
import fastifyMultipart from '@fastify/multipart';
|
|
import { WsRedisIoAdapter } from './ws/adapter/ws-redis.adapter';
|
|
import { InternalLogFilter } from './common/logger/internal-log-filter';
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create<NestFastifyApplication>(
|
|
AppModule,
|
|
new FastifyAdapter({
|
|
ignoreTrailingSlash: true,
|
|
ignoreDuplicateSlashes: true,
|
|
maxParamLength: 500,
|
|
}),
|
|
{
|
|
logger: new InternalLogFilter(),
|
|
},
|
|
);
|
|
|
|
app.setGlobalPrefix('api');
|
|
|
|
const redisIoAdapter = new WsRedisIoAdapter(app);
|
|
await redisIoAdapter.connectToRedis();
|
|
|
|
app.useWebSocketAdapter(redisIoAdapter);
|
|
|
|
await app.register(fastifyMultipart as any);
|
|
|
|
app
|
|
.getHttpAdapter()
|
|
.getInstance()
|
|
.addHook('preHandler', function (req, reply, done) {
|
|
if (
|
|
req.originalUrl.startsWith('/api') &&
|
|
!req.originalUrl.startsWith('/api/auth/setup')
|
|
) {
|
|
if (!req.raw?.['workspaceId']) {
|
|
throw new NotFoundException('Workspace not found');
|
|
}
|
|
done();
|
|
} else {
|
|
done();
|
|
}
|
|
});
|
|
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
whitelist: true,
|
|
stopAtFirstError: true,
|
|
transform: true,
|
|
}),
|
|
);
|
|
app.enableCors();
|
|
|
|
app.useGlobalInterceptors(new TransformHttpResponseInterceptor());
|
|
app.enableShutdownHooks();
|
|
|
|
await app.listen(process.env.PORT || 3000, '0.0.0.0');
|
|
}
|
|
|
|
bootstrap();
|