diff --git a/src/main.ts b/src/main.ts index 042367e..b86c648 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,20 +10,22 @@ import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; import { NestExpressApplication } from '@nestjs/platform-express'; import { AdminApiModule } from './modules/api/admin/admin.module'; import { OAuth2RouterModule } from './modules/static-front-end/oauth2-router/oauth2-router.module'; +import { ConfigurationService } from './modules/config/config.service'; dotenv.config(); async function bootstrap() { const app = await NestFactory.create(AppModule); + const config = app.get(ConfigurationService); - const config = new DocumentBuilder() + const docBuilder = new DocumentBuilder() .setTitle('Icy Network Authentication Server') .setDescription('Central authentication and management server') .setVersion('1.0') .addTag('admin') .addTag('oauth2') .build(); - const document = SwaggerModule.createDocument(app, config, { + const document = SwaggerModule.createDocument(app, docBuilder, { include: [AdminApiModule, OAuth2RouterModule], }); SwaggerModule.setup('api', app, document); @@ -47,7 +49,8 @@ async function bootstrap() { app.use( /\/((?!api).)*/, session({ - secret: process.env.SESSION_SECRET, + name: config.get('app.session_name'), + secret: config.get('app.session_secret'), resave: true, saveUninitialized: false, store: new RedisStore({ client: redisClient }), @@ -65,8 +68,10 @@ async function bootstrap() { app.setViewEngine('pug'); await app.listen( - parseInt(process.env.NEST_PORT, 10) || 3000, - process.env.NEST_HOST || '0.0.0.0', + parseInt(process.env.NEST_PORT, 10) || + config.get('app.port') || + 3000, + process.env.NEST_HOST || config.get('app.host') || '0.0.0.0', ); } bootstrap(); diff --git a/src/modules/config/config.providers.ts b/src/modules/config/config.providers.ts index af899a1..49059b0 100644 --- a/src/modules/config/config.providers.ts +++ b/src/modules/config/config.providers.ts @@ -17,6 +17,9 @@ export const configProviders: Provider[] = [ useValue: { app: { base_url: 'http://localhost:3000', + host: '0.0.0.0', + port: 3000, + session_name: '__sid', // generate the following with crypto.randomBytes(256 / 8).toString('hex') session_secret: 'change me!', challenge_secret: 'change me!', @@ -46,11 +49,11 @@ export const configProviders: Provider[] = [ username: 'root', password: 'root', database: 'icyauth', - entities: [__dirname + '/../**/*.entity{.ts,.js}'], + entities: ['dist/**/*.entity.js'], synchronize: true, - migrations: ['migration/*.js'], + migrations: ['dist/migration/*.js'], cli: { - migrationsDir: 'migration', + migrationsDir: 'src/migration', }, }, } as Configuration,