@nestjs/common#MiddlewareConsumer TypeScript Examples

The following examples show how to use @nestjs/common#MiddlewareConsumer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: middleware.helper.ts    From nestjs with MIT License 6 votes vote down vote up
export function forRoutesPath(options: MikroOrmMiddlewareModuleOptions, consumer: MiddlewareConsumer) {
  const isNestMiddleware = (consumer: MiddlewareConsumer): consumer is NestMiddlewareConsumer => {
    return typeof (consumer as any).httpAdapter === 'object';
  };

  const usingFastify = (consumer: NestMiddlewareConsumer) => {
    return consumer.httpAdapter.constructor.name.toLowerCase().startsWith('fastify');
  };

  return options.forRoutesPath ??
    (isNestMiddleware(consumer) && usingFastify(consumer) ? '(.*)' : '*');
}
Example #2
Source File: mikro-orm-core.module.ts    From nestjs with MIT License 6 votes vote down vote up
configure(consumer: MiddlewareConsumer): void {
    if (this.options.registerRequestContext === false) {
      return;
    }

    consumer
      .apply(MikroOrmMiddleware) // register request context automatically
      .forRoutes({ path: forRoutesPath(this.options, consumer), method: RequestMethod.ALL });
  }
Example #3
Source File: auth.module.ts    From relate with GNU General Public License v3.0 6 votes vote down vote up
configure(consumer: MiddlewareConsumer) {
        consumer.apply(cookieParser()).forRoutes('*');

        consumer
            .apply(ApiTokenMiddleware, AuthTokenMiddleware)
            .exclude(
                {
                    path: '/graphql',
                    method: RequestMethod.GET,
                },
                {
                    path: '/api-docs',
                    method: RequestMethod.GET,
                },
            )
            .forRoutes('*');
    }
Example #4
Source File: app.module.ts    From nest-js-quiz-manager with MIT License 5 votes vote down vote up
configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(ApiTokenCheckMiddleware)
      .forRoutes({ path: '/', method: RequestMethod.ALL });
  }
Example #5
Source File: app.module.ts    From edu-server with MIT License 5 votes vote down vote up
configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(PreauthMiddleware)
      .exclude(
        {
          path: 'course/(.*)',
          method: RequestMethod.GET,
        },
        {
          path: 'user/gamification',
          method: RequestMethod.GET,
        },
        {
          path: 'Doubt/(.*)',
          method: RequestMethod.GET,
        },
        {
          path: 'Doubt',
          method: RequestMethod.GET,
        },
        {
          path: 'Announcement/(.*)',
          method: RequestMethod.GET,
        },
        {
          path: 'Announcement',
          method: RequestMethod.GET,
        },
        {
          path: 'Mentor/(.*)',
          method: RequestMethod.GET,
        },
        {
          path: 'Mentor',
          method: RequestMethod.GET,
        },
      )
      .forRoutes({
        path: '*',
        method: RequestMethod.ALL,
      });
  }
Example #6
Source File: app.module.ts    From life-helper-backend with MIT License 5 votes vote down vote up
configure(consumer: MiddlewareConsumer): MiddlewareConsumer | void {
    /** 中间件列表 */
    const middlewares = [AuthMiddleware]

    consumer.apply(...middlewares).forRoutes({ path: '*', method: RequestMethod.ALL })
  }
Example #7
Source File: app.module.ts    From ironfish-api with Mozilla Public License 2.0 5 votes vote down vote up
configure(consumer: MiddlewareConsumer): void {
    consumer
      .apply(RequireSslMiddleware, ContextMiddleware)
      .forRoutes({ path: '*', method: RequestMethod.ALL });
  }
Example #8
Source File: mikro-orm-middleware.module.ts    From nestjs with MIT License 5 votes vote down vote up
configure(consumer: MiddlewareConsumer): void {
    consumer
      .apply(MultipleMikroOrmMiddleware)
      .forRoutes({ path: forRoutesPath(this.options, consumer), method: RequestMethod.ALL });
  }
Example #9
Source File: http-environment.module.ts    From nest-xray with MIT License 5 votes vote down vote up
public configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(AsyncHooksMiddleware)
      .forRoutes("/")
      .apply(HttpTracingMiddleware)
      .forRoutes("/");
  }
Example #10
Source File: index.ts    From bank-server with MIT License 5 votes vote down vote up
configure(consumer: MiddlewareConsumer): MiddlewareConsumer | void {
    consumer.apply(contextMiddleware).forRoutes('*');
  }
Example #11
Source File: auth.module.ts    From radiopanel with GNU General Public License v3.0 5 votes vote down vote up
configure(consumer: MiddlewareConsumer) {
	  	consumer
			.apply(LocalStrategyProvider)
			.forRoutes('/auth/login/local')
			.apply(DynamicStrategyProvider)
			.forRoutes('/auth/login/*');
	}
Example #12
Source File: app.module.ts    From NextJS-NestJS-GraphQL-Starter with MIT License 5 votes vote down vote up
configure(consumer: MiddlewareConsumer) {
    consumer.apply(AuthMiddleware).forRoutes('*');
  }