main.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { NestFactory } from '@nestjs/core';
  2. import { json } from 'express';
  3. import { AppModule } from './app.module';
  4. import * as cookieParser from 'cookie-parser';
  5. import { VersioningType } from '@nestjs/common';
  6. import * as session from 'express-session';
  7. import { emitGQLSchemaFile } from './gql-schema';
  8. async function bootstrap() {
  9. console.log(`Running in production: ${process.env.PRODUCTION}`);
  10. console.log(`Port: ${process.env.PORT}`);
  11. console.log(`Database: ${process.env.DATABASE_URL}`);
  12. const app = await NestFactory.create(AppModule);
  13. app.use(
  14. session({
  15. secret: process.env.SESSION_SECRET,
  16. }),
  17. );
  18. // Increase fil upload limit to 50MB
  19. app.use(
  20. json({
  21. limit: '100mb',
  22. }),
  23. );
  24. if (process.env.PRODUCTION === 'false') {
  25. console.log('Enabling CORS with development settings');
  26. app.enableCors({
  27. origin: process.env.WHITELISTED_ORIGINS.split(','),
  28. credentials: true,
  29. });
  30. } else {
  31. console.log('Enabling CORS with production settings');
  32. app.enableCors({
  33. origin: process.env.WHITELISTED_ORIGINS.split(','),
  34. credentials: true,
  35. });
  36. }
  37. app.enableVersioning({
  38. type: VersioningType.URI,
  39. });
  40. app.use(cookieParser());
  41. await app.listen(process.env.PORT || 3170);
  42. }
  43. if (!process.env.GENERATE_GQL_SCHEMA) {
  44. bootstrap();
  45. } else {
  46. emitGQLSchemaFile();
  47. }