@GrpcMethod('LiveService', 'FindOne') async findOne({slug}: { slug }, metadata: any) { const obj = await this.repoService.liveRepository.findOneOrFail({where: {slug}}); delete obj.password; return obj; }
private async getLive(client: Socket, liveSlug: string) { const {redisGet, redisSet} = RoomsService.redisClient(client); try { const result = await redisGet(liveSlug); if (!result) { throw new Error('Live not found in redis'); } return JSON.parse(result); } catch (e) { console.error(e); const service: LiveRpc = this.liveRpc.getService('LiveService'); const live = await service.findOne({slug: liveSlug}).toPromise(); await redisSet(liveSlug, JSON.stringify(live)); return live; } }
const bootstrap = async () => { const app = await NestFactory.create(AppModule, {cors: true}); app.useWebSocketAdapter(new RedisIoAdapter(app)); app.setGlobalPrefix('api'); app.connectMicroservice<MicroserviceOptions>({ transport: Transport.GRPC, options: { url: process.env.GRPC_SERVER_URL, package: 'live', protoPath: process.cwd() + "/src/core/shared/proto/live.proto", }, }); await app.startAllMicroservicesAsync(); await app.listen(process.env.SERVER_PORT, () => { Logger.log(`Server running on http://localhost:${process.env.SERVER_PORT}`, 'Bootstrap'); }); await createPeerServer(); }
const liveRpc: LiveRpc = this.liveRpc.getService('LiveService'); const { user_name, email, password, room } = data; const { redisSet } = RoomsService.redisClient(client);
@GrpcMethod('LiveService', 'Validate') async validate({slug, password}: { slug, password }, metadata: any) { const obj = await this.repoService.liveRepository.findOne({where: {slug}}); if (!obj || !obj.comparePassword(password)) { throw new Error('Not authorized'); } delete obj.password; return obj; }
transport: Transport.GRPC, options: { url: process.env.MICRO_LIVE_GENERATOR_GRPC_URL,