You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.5 KiB

2 years ago
import { InternalServerErrorException, Logger, ValidationPipe } from '@nestjs/common'
2 years ago
import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'
import * as session from 'express-session'
import * as passport from 'passport'
import { type NestExpressApplication } from '@nestjs/platform-express'
import * as cookieParser from 'cookie-parser'
import { IoAdapter } from '@nestjs/platform-socket.io'
2 years ago
2 years ago
async function bootstrap (): Promise<void> {
const logger = new Logger()
const app = await NestFactory.create<NestExpressApplication>(AppModule)
const port =
2 years ago
process.env.BACK_PORT !== undefined && process.env.BACK_PORT !== ''
? +process.env.BACK_PORT
2 years ago
: 3001
const cors = {
2 years ago
origin: new RegExp(
`^(http|ws)://${process.env.HOST ?? 'localhost'}(:\\d+)?$`
),
2 years ago
methods: 'GET, HEAD, PUT, PATCH, POST, DELETE, OPTIONS',
preflightContinue: false,
optionsSuccessStatus: 204,
credentials: true,
2 years ago
allowedHeaders:
['Accept', 'Content-Type', 'Authorization']
2 years ago
}
app.use(
session({
resave: false,
saveUninitialized: false,
secret:
2 years ago
process.env.JWT_SECRET !== undefined && process.env.JWT_SECRET !== ''
? process.env.JWT_SECRET
2 years ago
: 'secret'
})
2 years ago
)
app.use(cookieParser())
app.use(passport.initialize())
app.use(passport.session())
app.enableCors(cors)
app.useWebSocketAdapter(new IoAdapter(app))
await app.listen(port)
logger.log(`Application listening on port ${port}`)
2 years ago
}
bootstrap().catch((e) => {
2 years ago
throw new InternalServerErrorException(e)
})