Template
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { NestFactory, Reflector } from '@nestjs/core';
|
|
import * as session from 'express-session';
|
|
import { AppModule } from './app.module';
|
|
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
|
import { ClassSerializerInterceptor, INestApplication } from '@nestjs/common';
|
|
import { RedisStore } from 'connect-redis';
|
|
import { createClient } from 'redis';
|
|
|
|
async function bootstrap() {
|
|
const redisClient = createClient();
|
|
redisClient.connect().catch(console.error);
|
|
|
|
const app = await NestFactory.create(AppModule);
|
|
app.enableCors({ origin: 'http://localhost:3000', credentials: true });
|
|
app.setGlobalPrefix(process.env.API_PREFIX);
|
|
const config = new DocumentBuilder()
|
|
.setTitle('Concept Game')
|
|
.setDescription('Concept')
|
|
.setVersion('1.0')
|
|
.build();
|
|
const document = SwaggerModule.createDocument(app, config);
|
|
SwaggerModule.setup('api', app, document);
|
|
|
|
app.use(
|
|
session.default({
|
|
secret: process.env.SESSION_SECRET,
|
|
resave: false,
|
|
saveUninitialized: false,
|
|
name: 'concept.session',
|
|
store: new RedisStore({ client: redisClient, prefix: 'concept:' }),
|
|
}),
|
|
);
|
|
|
|
app.useGlobalInterceptors(
|
|
new ClassSerializerInterceptor(app.get(Reflector), {
|
|
// strategy: 'excludeAll', 👈 we'll talk about this later
|
|
excludeExtraneousValues: true,
|
|
}),
|
|
);
|
|
|
|
await app.listen(8765);
|
|
}
|
|
bootstrap();
|