Get port and upload path from config

Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
This commit is contained in:
David Mehren 2020-10-30 22:35:57 +01:00
parent 99dfa2d1fb
commit cd37eef45e
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
3 changed files with 21 additions and 8 deletions

View file

@ -5,10 +5,12 @@
*/
import { ValidationPipe } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { AppModule } from './app.module';
import { AppConfig } from './config/app.config';
import { NestConsoleLoggerService } from './logger/nest-console-logger.service';
async function bootstrap() {
@ -16,6 +18,8 @@ async function bootstrap() {
const logger = await app.resolve(NestConsoleLoggerService);
logger.log('Switching logger', 'AppBootstrap');
app.useLogger(logger);
const configService = app.get(ConfigService);
const appConfig = configService.get<AppConfig>('appConfig');
const swaggerOptions = new DocumentBuilder()
.setTitle('HedgeDoc')
@ -31,12 +35,13 @@ async function bootstrap() {
transform: true,
}),
);
// TODO: Get uploads directory from config
app.useStaticAssets('uploads', {
prefix: '/uploads',
});
await app.listen(3000);
logger.log('Listening on port 3000', 'AppBootstrap');
if (appConfig.media.backend.use === 'filesystem') {
app.useStaticAssets('uploads', {
prefix: appConfig.media.backend.filesystem.uploadPath,
});
}
await app.listen(appConfig.port);
logger.log(`Listening on port ${appConfig.port}`, 'AppBootstrap');
}
bootstrap();