2021-01-05 21:12:38 +00:00
|
|
|
/*
|
2022-06-21 14:16:40 +00:00
|
|
|
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
2021-01-05 21:12:38 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
2020-10-30 21:35:57 +00:00
|
|
|
import { ConfigService } from '@nestjs/config';
|
2022-06-19 19:23:56 +00:00
|
|
|
import { NestFactory } from '@nestjs/core';
|
2020-10-24 09:32:23 +00:00
|
|
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
2021-08-29 16:45:46 +00:00
|
|
|
|
2022-06-19 19:23:56 +00:00
|
|
|
import { setupApp } from './app-init';
|
2020-07-25 18:26:10 +00:00
|
|
|
import { AppModule } from './app.module';
|
2020-10-30 21:35:57 +00:00
|
|
|
import { AppConfig } from './config/app.config';
|
2021-08-31 11:36:13 +00:00
|
|
|
import { AuthConfig } from './config/auth.config';
|
2023-06-25 19:29:50 +00:00
|
|
|
import { Loglevel } from './config/loglevel.enum';
|
2021-01-15 15:57:04 +00:00
|
|
|
import { MediaConfig } from './config/media.config';
|
2021-04-02 17:08:30 +00:00
|
|
|
import { ConsoleLoggerService } from './logger/console-logger.service';
|
2020-07-21 19:24:56 +00:00
|
|
|
|
2021-02-27 16:41:32 +00:00
|
|
|
async function bootstrap(): Promise<void> {
|
2022-06-19 19:23:56 +00:00
|
|
|
// Initialize AppModule
|
2021-04-02 17:08:30 +00:00
|
|
|
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
|
2023-06-25 19:29:50 +00:00
|
|
|
// ConsoleLoggerService only uses the loglevel, so we can give it an incomplete AppConfig to log everything
|
|
|
|
// This Logger instance will be replaced by a proper one with config from DI below
|
|
|
|
logger: new ConsoleLoggerService({ loglevel: Loglevel.TRACE } as AppConfig),
|
2021-04-02 17:08:30 +00:00
|
|
|
});
|
2022-06-19 19:23:56 +00:00
|
|
|
|
|
|
|
// Set up our custom logger
|
2021-04-02 17:08:30 +00:00
|
|
|
const logger = await app.resolve(ConsoleLoggerService);
|
2020-09-27 19:48:42 +00:00
|
|
|
logger.log('Switching logger', 'AppBootstrap');
|
|
|
|
app.useLogger(logger);
|
2022-06-19 19:23:56 +00:00
|
|
|
|
|
|
|
// Initialize config and abort if we don't have a valid config
|
2020-10-30 21:35:57 +00:00
|
|
|
const configService = app.get(ConfigService);
|
|
|
|
const appConfig = configService.get<AppConfig>('appConfig');
|
2021-08-31 11:36:13 +00:00
|
|
|
const authConfig = configService.get<AuthConfig>('authConfig');
|
2021-01-15 15:57:04 +00:00
|
|
|
const mediaConfig = configService.get<MediaConfig>('mediaConfig');
|
2022-04-02 21:45:46 +00:00
|
|
|
|
2022-06-21 14:16:40 +00:00
|
|
|
if (!appConfig || !authConfig || !mediaConfig) {
|
2021-04-29 14:22:01 +00:00
|
|
|
logger.error('Could not initialize config, aborting.', 'AppBootstrap');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2022-06-19 19:23:56 +00:00
|
|
|
// Call common setup function which handles the rest
|
|
|
|
// Setup code must be added there!
|
2022-06-21 14:16:40 +00:00
|
|
|
await setupApp(app, appConfig, authConfig, mediaConfig, logger);
|
2021-08-31 11:36:13 +00:00
|
|
|
|
2022-06-19 19:23:56 +00:00
|
|
|
// Start the server
|
2020-10-30 21:35:57 +00:00
|
|
|
await app.listen(appConfig.port);
|
2023-10-07 09:01:58 +00:00
|
|
|
logger.warn(`Listening on port ${appConfig.port}`, 'AppBootstrap');
|
2020-07-21 19:24:56 +00:00
|
|
|
}
|
|
|
|
|
2021-02-24 20:08:08 +00:00
|
|
|
void bootstrap();
|