bootstrap.ts 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. import { NestFactory } from '@nestjs/core';
  2. import { getConfig, setConfig, VendureConfig } from './config/vendure-config';
  3. /**
  4. * Bootstrap the Vendure server.
  5. */
  6. export async function bootstrap(userConfig?: Partial<VendureConfig>) {
  7. if (userConfig) {
  8. setConfig(userConfig);
  9. }
  10. // Entities *must* be loaded after the user config is set in order for the
  11. // base VendureEntity to be correctly configured with the primary key type
  12. // specified in the EntityIdStrategy.
  13. // tslint:disable-next-line:whitespace
  14. const entities = await import('./entity/entities');
  15. setConfig({
  16. dbConnectionOptions: {
  17. entities: entities.coreEntities,
  18. },
  19. });
  20. // The AppModule *must* be loaded only after the entities have been set in the
  21. // config, so that they are available when the AppModule decorator is evaluated.
  22. // tslint:disable-next-line:whitespace
  23. const appModule = await import('./app.module');
  24. const config = getConfig();
  25. const app = await NestFactory.create(appModule.AppModule, { cors: config.cors });
  26. await app.listen(config.port);
  27. }