add host, port to config, rename session

This commit is contained in:
Evert Prants 2022-09-12 21:55:02 +03:00
parent b4befa02fc
commit 6195f879db
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 16 additions and 8 deletions

View File

@ -10,20 +10,22 @@ import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { NestExpressApplication } from '@nestjs/platform-express'; import { NestExpressApplication } from '@nestjs/platform-express';
import { AdminApiModule } from './modules/api/admin/admin.module'; import { AdminApiModule } from './modules/api/admin/admin.module';
import { OAuth2RouterModule } from './modules/static-front-end/oauth2-router/oauth2-router.module'; import { OAuth2RouterModule } from './modules/static-front-end/oauth2-router/oauth2-router.module';
import { ConfigurationService } from './modules/config/config.service';
dotenv.config(); dotenv.config();
async function bootstrap() { async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule); const app = await NestFactory.create<NestExpressApplication>(AppModule);
const config = app.get(ConfigurationService);
const config = new DocumentBuilder() const docBuilder = new DocumentBuilder()
.setTitle('Icy Network Authentication Server') .setTitle('Icy Network Authentication Server')
.setDescription('Central authentication and management server') .setDescription('Central authentication and management server')
.setVersion('1.0') .setVersion('1.0')
.addTag('admin') .addTag('admin')
.addTag('oauth2') .addTag('oauth2')
.build(); .build();
const document = SwaggerModule.createDocument(app, config, { const document = SwaggerModule.createDocument(app, docBuilder, {
include: [AdminApiModule, OAuth2RouterModule], include: [AdminApiModule, OAuth2RouterModule],
}); });
SwaggerModule.setup('api', app, document); SwaggerModule.setup('api', app, document);
@ -47,7 +49,8 @@ async function bootstrap() {
app.use( app.use(
/\/((?!api).)*/, /\/((?!api).)*/,
session({ session({
secret: process.env.SESSION_SECRET, name: config.get<string>('app.session_name'),
secret: config.get<string>('app.session_secret'),
resave: true, resave: true,
saveUninitialized: false, saveUninitialized: false,
store: new RedisStore({ client: redisClient }), store: new RedisStore({ client: redisClient }),
@ -65,8 +68,10 @@ async function bootstrap() {
app.setViewEngine('pug'); app.setViewEngine('pug');
await app.listen( await app.listen(
parseInt(process.env.NEST_PORT, 10) || 3000, parseInt(process.env.NEST_PORT, 10) ||
process.env.NEST_HOST || '0.0.0.0', config.get<number>('app.port') ||
3000,
process.env.NEST_HOST || config.get<string>('app.host') || '0.0.0.0',
); );
} }
bootstrap(); bootstrap();

View File

@ -17,6 +17,9 @@ export const configProviders: Provider<any>[] = [
useValue: { useValue: {
app: { app: {
base_url: 'http://localhost:3000', 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') // generate the following with crypto.randomBytes(256 / 8).toString('hex')
session_secret: 'change me!', session_secret: 'change me!',
challenge_secret: 'change me!', challenge_secret: 'change me!',
@ -46,11 +49,11 @@ export const configProviders: Provider<any>[] = [
username: 'root', username: 'root',
password: 'root', password: 'root',
database: 'icyauth', database: 'icyauth',
entities: [__dirname + '/../**/*.entity{.ts,.js}'], entities: ['dist/**/*.entity.js'],
synchronize: true, synchronize: true,
migrations: ['migration/*.js'], migrations: ['dist/migration/*.js'],
cli: { cli: {
migrationsDir: 'migration', migrationsDir: 'src/migration',
}, },
}, },
} as Configuration, } as Configuration,