How to use @nestjs/core - 10 common examples

To help you get started, we’ve selected a few @nestjs/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mpcast / mpcast-server / packages / core / src / bootstrap.ts View on Github external
app = await NestFactory.create(appModule.AppModule, {
        cors: config.cors,
        logger: new Logger(),
    });
    app.setGlobalPrefix('api');
    // DefaultLogger.restoreOriginalLogLevel();
    // app.useLogger(new Logger());
    app.use(helmet());
    app.use(compression());
    app.use(bodyParser.json({ limit: '1mb' }));
    app.use(bodyParser.urlencoded({ extended: true }));
    // app.use(rateLimit({ max: 1000, windowMs: 15 * 60 * 1000 }));
    app.useGlobalFilters(new HttpExceptionFilter());
    app.useGlobalPipes(new ValidationPipe());
    app.useGlobalInterceptors(
        new TransformInterceptor(new Reflector()),
        new ErrorInterceptor(new Reflector()),
        new LoggingInterceptor(),
    );
    // const options = new DocumentBuilder()
    //   .setTitle('播客系统服务端 API')
    //   .setDescription('The Podcast API')
    //   .setVersion('2.0')
    //   .addTag('Podcast Server')
    //   .build();
    // const document = SwaggerModule.createDocument(app, options);
    // SwaggerModule.setup('apidoc', app, document);

    // return await app.listen(appConfig.APP.PORT);
    await app.listen(config.port, config.hostname);
    logWelcomeMessage(config);
    return app;
github new-eden-social / new-eden-social / src / services / post / server.ts View on Github external
async function bootstrap() {
  const HTTP_PORT = parseInt(process.env.HTTP_PORT, 10) || 3000; // Default to 3000
  const GRPC_PORT = parseInt(process.env.GRPC_PORT, 10) || 4000; // Default to 4000

  const app = await NestFactory.create(PostModule);

  app.connectMicroservice({
    transport: Transport.GRPC,
    options: {
      url: `0.0.0.0:${GRPC_PORT}`,
      package: 'post',
      protoPath: join(__dirname, 'src/grpc/post.proto'),
    },
  });

  app.connectMicroservice({
    transport: Transport.REDIS,
    options: {
      url: process.env.REDIS_HOST,
    },
  });
github new-eden-social / new-eden-social / src / services / search / server.ts View on Github external
async function bootstrap() {
  const HTTP_PORT = parseInt(process.env.HTTP_PORT, 10) || 3000; // Default to 3000
  const GRPC_PORT = parseInt(process.env.GRPC_PORT, 10) || 4000; // Default to 4000

  const app = await NestFactory.create(SearchModule);

  app.connectMicroservice({
    transport: Transport.GRPC,
    options: {
      url: `0.0.0.0:${GRPC_PORT}`,
      package: 'search',
      protoPath: join(__dirname, 'src/grpc/search.proto'),
    },
  });

  await app.startAllMicroservicesAsync();
  await app.listen(HTTP_PORT);
}
github vendure-ecommerce / vendure / packages / core / src / bootstrap.ts View on Github external
async function bootstrapWorkerInternal(userConfig: Partial): Promise {
    const config = disableSynchronize(await preBootstrapConfig(userConfig));
    if (!config.workerOptions.runInMainProcess && (config.logger as any).setDefaultContext) {
        (config.logger as any).setDefaultContext('Vendure Worker');
    }
    Logger.useLogger(config.logger);
    Logger.info(`Bootstrapping Vendure Worker (pid: ${process.pid})...`);

    const workerModule = await import('./worker/worker.module');
    DefaultLogger.hideNestBoostrapLogs();
    const workerApp = await NestFactory.createMicroservice(workerModule.WorkerModule, {
        transport: config.workerOptions.transport,
        logger: new Logger(),
        options: config.workerOptions.options,
    });
    DefaultLogger.restoreOriginalLogLevel();
    workerApp.useLogger(new Logger());
    workerApp.enableShutdownHooks();

    // A work-around to correctly handle errors when attempting to start the
    // microservice server listening.
    // See https://github.com/nestjs/nest/issues/2777
    // TODO: Remove if & when the above issue is resolved.
    await new Promise((resolve, reject) => {
        (workerApp as any).server.server.on('error', (e: any) => {
            reject(e);
        });
github mpcast / mpcast-server / src / main.ts View on Github external
async function bootstrap() {
  const app = await NestFactory.create(AppModule, isProdMode ? { logger: false } : null);
  // app.use()
  app.use(helmet());
  app.use(compression());
  app.use(bodyParser.json({ limit: '1mb' }));
  app.useGlobalFilters(new HttpExceptionFilter());
  app.useGlobalPipes(new ValidationPipe());
  app.useGlobalInterceptors(
    new TransformInterceptor(new Reflector()),
    new ErrorInterceptor(new Reflector()),
    new LoggingInterceptor(),
  );
  const options = new DocumentBuilder()
    .setTitle('播客系统服务端')
    .setDescription('The Podcast API')
    .setVersion('2.0')
    .addTag('Podcast Server')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('api', app, document);
  return await app.listen(appConfig.APP.PORT);
}
github mpcast / mpcast-server / src / main.ts View on Github external
async function bootstrap() {
  const app = await NestFactory.create(AppModule, isProdMode ? { logger: false } : null);
  // app.use()
  app.use(helmet());
  app.use(compression());
  app.use(bodyParser.json({ limit: '1mb' }));
  app.useGlobalFilters(new HttpExceptionFilter());
  app.useGlobalPipes(new ValidationPipe());
  app.useGlobalInterceptors(
    new TransformInterceptor(new Reflector()),
    new ErrorInterceptor(new Reflector()),
    new LoggingInterceptor(),
  );
  const options = new DocumentBuilder()
    .setTitle('播客系统服务端')
    .setDescription('The Podcast API')
    .setVersion('2.0')
    .addTag('Podcast Server')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('api', app, document);
  return await app.listen(appConfig.APP.PORT);
}
github notadd / notadd / apps / noxus / cms / lib / main.js View on Github external
async function bootstrap() {
    const app = await core_1.NestFactory.create(cms_module_1.CmsModule, { bodyParser: false });
    app.connectMicroservice({
        transport: transport_enum_1.Transport.GRPC,
        options: {
            url: `${options.host}:3001`,
            package: 'noxus',
            protoPath: `${__dirname}/main.proto`
        }
    });
    await app.startAllMicroservicesAsync();
    // await app.listen(options.graphqlPort);
    await app.listen(9001);
}
exports.bootstrap = bootstrap;
github dzzzzzy / Nestjs-Learning / demo / crud-demo / src / main.ts View on Github external
async function bootstrap() {
    const app = await NestFactory.create(AppModule, new FastifyAdapter());  // 创建应用程序实例,此时所有被 AppModule 导入的其他模块的所有实例都会被加载

    // 配置文件中如果启用了 IDE,则向 fastify 注册这个 IDE 插件
    if (graphqlConfig.ide.enable) {
        app.use(graphqlConfig.ide.prefix, fastifyGraphiQL({ endpointURL: graphqlConfig.ide.endpointURL }));
    }

    // 配置 bodyParser 中间件
    app.use('/graphql', bodyParser.json());

    // 获取上下文中的 GraphQLFactory,然后解析 graphql 文件,并创建 graphql schema
    const graphQLFactory = app.get(GraphQLFactory);
    const typeDefs = graphQLFactory.mergeTypesByPaths(graphqlConfig.typeDefsPath);
    const schema = graphQLFactory.createSchema({ typeDefs });
    app.use('/graphql', fastifyGraphQL(req => ({ schema, rootValue: req })));

    await app.listen(3000);  // 使用3000端口监听应用程序
github vendure-ecommerce / vendure / packages / testing / src / test-server.ts View on Github external
private async bootstrapForTesting(
        userConfig: Partial,
    ): Promise<[INestApplication, INestMicroservice | undefined]> {
        const config = await preBootstrapConfig(userConfig);
        Logger.useLogger(config.logger);
        const appModule = await import('@vendure/core/dist/app.module');
        try {
            DefaultLogger.hideNestBoostrapLogs();
            const app = await NestFactory.create(appModule.AppModule, { cors: config.cors, logger: false });
            let worker: INestMicroservice | undefined;
            await app.listen(config.port);
            if (config.workerOptions.runInMainProcess) {
                const workerModule = await import('@vendure/core/dist/worker/worker.module');
                worker = await NestFactory.createMicroservice(workerModule.WorkerModule, {
                    transport: config.workerOptions.transport,
                    logger: new Logger(),
                    options: config.workerOptions.options,
                });
                await worker.listenAsync();
            }
            DefaultLogger.restoreOriginalLogLevel();
            return [app, worker];
        } catch (e) {
            console.log(e);
            throw e;
        }
    }
}
github notadd / nt-module-user / test / user-module / app.module.ts View on Github external
constructor(
        @Inject(ModulesContainer) private readonly modulesContainer: ModulesContainer,
        @InjectRepository(Resource) private readonly resourceRepo: Repository,
        @InjectRepository(Permission) private readonly permissionRepo: Repository,

    ) {
        this.metadataScanner = new MetadataScanner();
    }