2021-01-05 16:12:38 -05:00
|
|
|
/*
|
2021-01-06 15:36:07 -05:00
|
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
2021-01-05 16:12:38 -05:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2020-07-25 14:26:10 -04:00
|
|
|
import { ValidationPipe } from '@nestjs/common';
|
2020-10-30 17:35:57 -04:00
|
|
|
import { ConfigService } from '@nestjs/config';
|
2020-07-25 14:26:10 -04:00
|
|
|
import { NestFactory } from '@nestjs/core';
|
2020-10-24 05:32:23 -04:00
|
|
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
2020-07-26 10:53:43 -04:00
|
|
|
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
2020-07-25 14:26:10 -04:00
|
|
|
import { AppModule } from './app.module';
|
2020-10-30 17:35:57 -04:00
|
|
|
import { AppConfig } from './config/app.config';
|
2020-09-27 15:48:42 -04:00
|
|
|
import { NestConsoleLoggerService } from './logger/nest-console-logger.service';
|
2021-01-15 10:57:04 -05:00
|
|
|
import { MediaConfig } from './config/media.config';
|
2020-07-21 15:24:56 -04:00
|
|
|
|
2020-07-25 14:26:10 -04:00
|
|
|
async function bootstrap() {
|
2020-10-24 05:32:23 -04:00
|
|
|
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
2020-09-27 15:48:42 -04:00
|
|
|
const logger = await app.resolve(NestConsoleLoggerService);
|
|
|
|
logger.log('Switching logger', 'AppBootstrap');
|
|
|
|
app.useLogger(logger);
|
2020-10-30 17:35:57 -04:00
|
|
|
const configService = app.get(ConfigService);
|
|
|
|
const appConfig = configService.get<AppConfig>('appConfig');
|
2021-01-15 10:57:04 -05:00
|
|
|
const mediaConfig = configService.get<MediaConfig>('mediaConfig');
|
2020-07-26 10:53:43 -04:00
|
|
|
|
|
|
|
const swaggerOptions = new DocumentBuilder()
|
|
|
|
.setTitle('HedgeDoc')
|
|
|
|
.setVersion('2.0-dev')
|
2021-01-16 11:45:14 -05:00
|
|
|
.addSecurity('token', {
|
|
|
|
type: 'http',
|
|
|
|
scheme: 'bearer',
|
|
|
|
})
|
2020-07-26 10:53:43 -04:00
|
|
|
.build();
|
|
|
|
const document = SwaggerModule.createDocument(app, swaggerOptions);
|
|
|
|
SwaggerModule.setup('apidoc', app, document);
|
|
|
|
|
2020-07-25 14:26:10 -04:00
|
|
|
app.useGlobalPipes(
|
|
|
|
new ValidationPipe({
|
|
|
|
forbidUnknownValues: true,
|
|
|
|
skipMissingProperties: false,
|
|
|
|
transform: true,
|
|
|
|
}),
|
|
|
|
);
|
2021-01-15 10:57:04 -05:00
|
|
|
if (mediaConfig.backend.use === 'filesystem') {
|
2020-10-30 17:35:57 -04:00
|
|
|
app.useStaticAssets('uploads', {
|
2021-01-15 10:57:04 -05:00
|
|
|
prefix: mediaConfig.backend.filesystem.uploadPath,
|
2020-10-30 17:35:57 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
await app.listen(appConfig.port);
|
|
|
|
logger.log(`Listening on port ${appConfig.port}`, 'AppBootstrap');
|
2020-07-21 15:24:56 -04:00
|
|
|
}
|
|
|
|
|
2020-07-25 14:26:10 -04:00
|
|
|
bootstrap();
|