icynet-auth-server/src/main.ts

52 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-03-09 18:37:04 +00:00
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as dotenv from 'dotenv';
import * as session from 'express-session';
2022-03-20 14:50:12 +00:00
import * as connectRedis from 'connect-redis';
import * as redis from 'redis';
2022-08-17 18:56:47 +00:00
import * as cookieParser from 'cookie-parser';
2022-03-09 18:37:04 +00:00
import { join } from 'path';
import { NestExpressApplication } from '@nestjs/platform-express';
dotenv.config();
async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule);
2022-03-20 14:50:12 +00:00
const RedisStore = connectRedis(session);
const redisClient = redis.createClient({
host: 'localhost',
port: 6379,
});
// app.use(express.urlencoded());
2022-08-17 18:56:47 +00:00
app.use(cookieParser());
2022-03-20 14:50:12 +00:00
2022-03-26 07:22:14 +00:00
// Production servers have to be behind a proxy.
if (process.env.NODE_ENV === 'production') {
app.set('trust proxy');
}
2022-03-09 18:37:04 +00:00
app.use(
session({
secret: process.env.SESSION_SECRET,
resave: true,
saveUninitialized: false,
2022-03-20 14:50:12 +00:00
store: new RedisStore({ client: redisClient }),
2022-03-09 18:37:04 +00:00
cookie: {
sameSite: 'lax',
secure: process.env.NODE_ENV === 'production',
},
}),
);
app.useStaticAssets(join(__dirname, '..', 'public'), {
prefix: '/public/',
});
app.setBaseViewsDir(join(__dirname, '..', 'views'));
app.setViewEngine('pug');
2022-08-18 07:12:02 +00:00
await app.listen(3000, '0.0.0.0');
2022-03-09 18:37:04 +00:00
}
bootstrap();