71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import { AppModule } from './app.module';
|
|
import * as dotenv from 'dotenv';
|
|
import * as session from 'express-session';
|
|
import * as connectRedis from 'connect-redis';
|
|
import * as redis from 'redis';
|
|
import * as cookieParser from 'cookie-parser';
|
|
import { join } from 'path';
|
|
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';
|
|
|
|
dotenv.config();
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
|
|
|
const config = 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, {
|
|
include: [AdminApiModule, OAuth2RouterModule],
|
|
});
|
|
SwaggerModule.setup('api', app, document);
|
|
|
|
const RedisStore = connectRedis(session);
|
|
const redisClient = redis.createClient({
|
|
url: process.env.REDIS_URL || 'redis://localhost:6379',
|
|
legacyMode: true,
|
|
});
|
|
redisClient.connect();
|
|
|
|
// app.use(express.urlencoded());
|
|
app.use(cookieParser());
|
|
|
|
// Production servers have to be behind a proxy.
|
|
if (process.env.NODE_ENV === 'production') {
|
|
app.set('trust proxy');
|
|
}
|
|
|
|
app.use(
|
|
session({
|
|
secret: process.env.SESSION_SECRET,
|
|
resave: true,
|
|
saveUninitialized: false,
|
|
store: new RedisStore({ client: redisClient }),
|
|
cookie: {
|
|
sameSite: 'strict',
|
|
secure: process.env.NODE_ENV === 'production',
|
|
},
|
|
}),
|
|
);
|
|
|
|
app.useStaticAssets(join(__dirname, '..', 'public'), {
|
|
prefix: '/public/',
|
|
});
|
|
app.setBaseViewsDir(join(__dirname, '..', 'views'));
|
|
app.setViewEngine('pug');
|
|
|
|
await app.listen(
|
|
parseInt(process.env.NEST_PORT, 10) || 3000,
|
|
process.env.NEST_HOST || '0.0.0.0',
|
|
);
|
|
}
|
|
bootstrap();
|