LocChat/server/main.ts

38 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2021-11-16 21:14:46 -05:00
import './env';
import * as fs from 'fs';
import { NestFactory } from '@nestjs/core';
2021-11-30 17:40:07 -05:00
import { Logger } from '@nestjs/common';
2021-11-16 21:14:46 -05:00
import { join } from 'path';
import { NestExpressApplication } from '@nestjs/platform-express';
2021-11-20 20:18:58 -05:00
import * as cookieParser from 'cookie-parser';
import { AppModule } from './app.module';
2021-11-30 17:40:07 -05:00
import * as morgan from 'morgan';
2021-11-16 21:14:46 -05:00
async function bootstrap() {
let httpsOptions;
2021-11-30 17:40:07 -05:00
if (process.env.USE_SSL === 'true') {
2021-11-16 21:14:46 -05:00
httpsOptions = {
key: fs.readFileSync('./private-key.pem'),
cert: fs.readFileSync('./public-cert.pem'),
};
}
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
httpsOptions,
2021-11-20 20:18:58 -05:00
logger: ['verbose'],
2021-11-16 21:14:46 -05:00
});
2021-11-20 20:18:58 -05:00
app.use(cookieParser());
2021-11-16 21:14:46 -05:00
app.useStaticAssets(join(__dirname, '..', 'static'));
2021-11-23 16:04:12 -05:00
app.setBaseViewsDir(join(__dirname, '..', 'views'));
2021-11-16 21:14:46 -05:00
app.setViewEngine('hbs');
2021-11-30 17:40:07 -05:00
const logger = new Logger('Request');
app.use(
morgan('tiny', {
stream: {
write: (message) => logger.log(message.replace('\n', '')),
},
}),
);
2021-11-16 21:14:46 -05:00
await app.listen(process.env.PORT);
}
bootstrap();