How to use @nestjs/platform-ws - 8 common examples

To help you get started, weโ€™ve selected a few @nestjs/platform-ws 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 TimurRK / nestjs-example / src / main.ts View on Github external
const server = express();

  const app = await NestFactory.create(AppModule, new ExpressAdapter(server));

  app.use(helmet());
  app.use(cookieParser());
  app.enableCors(corsOptions);

  app.useGlobalPipes(
    new ValidationPipe({
      transform: true,
    })
  );

  // tslint:disable-next-line: no-unsafe-any
  app.useWebSocketAdapter(new WsAdapter(app));

  app.use('/voyager', voyagerMiddleware({ endpointUrl: '/graphql' }));

  const options = new DocumentBuilder()
    .setTitle('Auth example')
    .setDescription('The auth API description')
    .setVersion('1.0')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('swagger', app, document);

  await app.listen(8080);
}
bootstrap();
github nayutaco / ptarmigan / ptarmapi / src / main.ts View on Github external
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.useWebSocketAdapter(new WsAdapter(app));

  // swagger setting
  const options = new DocumentBuilder()
    .setTitle('ptarmigan REST-API')
    .setDescription('Lightning Network implementation ptarmigan REST-API')
    .addBearerAuth('Authorization', 'header')
    .setVersion('0.2')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('api', app, document);

  const config = ConfigService;
  Logger.log('ptarmdRpcPort: ' + config.get('ptarmigan.ptarmdRpcPort'));
  Logger.log('ptarmdHost: + ' + config.get('ptarmigan.ptarmdHost'));
  Logger.log('bitcoindRpcPort: ' + config.get('ptarmigan.bitcoindRpcPort'));
  Logger.log('bitcoindHost: ' + config.get('ptarmigan.bitcoindHost'));
github danielwii / asuna-node-server / src / bootstrap.ts View on Github external
app.use(morgan('combined'));

  const limit = configLoader.loadConfig(ConfigKeys.PAYLOAD_LIMIT, '20mb');
  logger.log(`set json payload limit to ${limit}`);
  app.use(bodyParser.json({ limit }));
  app.use(bodyParser.urlencoded({ limit, extended: true }));

  app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)));
  app.useGlobalInterceptors(new LoggerInterceptor());
  app.useGlobalFilters(new AnyExceptionFilter());
  app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true }));

  if (options.redisMode === 'redis') {
    app.useWebSocketAdapter(new (require('./modules/ws/redis.adapter').RedisIoAdapter)(app));
  } else if (options.redisMode === 'ws') {
    app.useWebSocketAdapter(new (require('@nestjs/platform-ws').WsAdapter)(app));
  }

  // app.use(csurf());
  // app.enableCors(); fixme temp disable for allow OPTIONS
  app.enableShutdownHooks();

  if (AsunaContext.isDebugMode) {
    logger.log('[X] debug mode is enabled');
  }

  // --------------------------------------------------------------
  // Setup Swagger
  // --------------------------------------------------------------

  if (configLoader.loadBoolConfig(ConfigKeys.SWAGGER)) {
    logger.log('[X] init swagger at /swagger');
github wix / quix / quix-frontend / service / src / main.ts View on Github external
await createInitialSchemaIfNeeded(conn, env.DbName, logger);
      await checkSchemaVersion(conn, logger);

      await conn.close();
    }
  } else {
    await new Promise(resolve => setTimeout(resolve, 3000)); // let master process do it's thing, create schema and all;
  }

  const app = await NestFactory.create(AppModule);

  app.useStaticAssets(env.localStaticsPath);
  app.setBaseViewsDir(env.localStaticsPath);
  app.engine('.vm', velocityEngine());
  app.use(cookieParser());
  app.useWebSocketAdapter(new WsAdapter(app));
  await app.listen(env.HttpPort);
}
bootstrap();
github radarsu / rpc-websocket-client / __tests-utils__ / server.ts View on Github external
const bootstrap = async () => {

    const mod = await Test.createTestingModule({
        imports: [EventsModule],
    }).compile();

    app = mod.createNestApplication();
    app.useWebSocketAdapter(new WsAdapter());
    await app.listen(7000);

};
github radarsu / rpc-websocket-client / __tests__ / rpc-websocket-client.spec.ts View on Github external
beforeAll(async () => {
        const mod = await Test.createTestingModule({
            imports: [EventsModule],
        }).compile();

        app = mod.createNestApplication();
        app.useWebSocketAdapter(new WsAdapter());
        await app.listen(testConfig.port);
    });
github fischermatte / geolud / geolud-server-node / src / main.ts View on Github external
async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: console,
    cors: true,
  });
  await app.useWebSocketAdapter(new WsAdapter(app)).listen(port);
}
bootstrap();
github nestjs / nest / sample / 16-gateways-ws / src / main.ts View on Github external
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.useWebSocketAdapter(new WsAdapter(app));
  await app.listen(3000);
}
bootstrap();

@nestjs/platform-ws

Nest - modern, fast, powerful node.js web framework (@platform-ws)

MIT
Latest version published 13 days ago

Package Health Score

95 / 100
Full package analysis

Popular @nestjs/platform-ws functions

Similar packages