Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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(NotificationModule);
app.connectMicroservice({
transport: Transport.GRPC,
options: {
url: `0.0.0.0:${GRPC_PORT}`,
package: 'notification',
protoPath: join(__dirname, 'src/grpc/notification.proto'),
},
});
app.connectMicroservice({
transport: Transport.REDIS,
options: {
url: process.env.REDIS_HOST,
},
});
await app.startAllMicroservicesAsync();
await app.listen(HTTP_PORT);
private createClient(
options: CheckGRPCServiceOptions,
): NestJSMicroservices.ClientGrpc {
const {
timeout,
healthServiceName,
healthServiceCheck,
...grpcOptions
} = options;
// TODO: Remove `as any` as soon nestjs/nest#2240 gets merged
return this.nestJsMicroservices.ClientProxyFactory.create({
transport: Transport.GRPC,
options: grpcOptions as GrpcOptionsOptions,
}) as any;
}
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(AllianceModule);
app.connectMicroservice({
transport: Transport.GRPC,
options: {
url: `0.0.0.0:${GRPC_PORT}`,
package: 'alliance',
protoPath: join(__dirname, 'src/grpc/alliance.proto'),
},
});
await app.startAllMicroservicesAsync();
await app.listen(HTTP_PORT);
}
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(FollowModule);
app.connectMicroservice({
transport: Transport.GRPC,
options: {
url: `0.0.0.0:${GRPC_PORT}`,
package: 'follow',
protoPath: join(__dirname, 'src/grpc/follow.proto'),
},
});
await app.startAllMicroservicesAsync();
await app.listen(HTTP_PORT);
}
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(CommentModule);
app.connectMicroservice({
transport: Transport.GRPC,
options: {
url: `0.0.0.0:${GRPC_PORT}`,
package: 'post',
protoPath: join(__dirname, 'src/grpc/post.proto'),
},
});
await app.startAllMicroservicesAsync();
await app.listen(HTTP_PORT);
}
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(HashtagModule);
app.connectMicroservice({
transport: Transport.GRPC,
options: {
url: `0.0.0.0:${GRPC_PORT}`,
package: 'hashtag',
protoPath: join(__dirname, 'src/grpc/hashtag.proto'),
},
});
await app.startAllMicroservicesAsync();
await app.listen(HTTP_PORT);
}
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(CorporationModule);
app.connectMicroservice({
transport: Transport.GRPC,
options: {
url: `0.0.0.0:${GRPC_PORT}`,
package: 'corporation',
protoPath: join(__dirname, 'src/grpc/corporation.proto'),
},
});
await app.startAllMicroservicesAsync();
await app.listen(HTTP_PORT);
}
bootstrap();
beforeEach(async () => {
const module = await Test.createTestingModule({
controllers: [GrpcController],
}).compile();
server = express();
app = module.createNestApplication(server);
app.connectMicroservice({
transport: Transport.GRPC,
options: {
package: 'math',
protoPath: join(__dirname, '../src/grpc/math.proto'),
},
});
await app.startAllMicroservicesAsync();
await app.init();
});
export function generateGrpcOptions(url: string, packageName: string, protoFileName: string): GrpcOptions {
return {
transport: Transport.GRPC,
options: {
url,
package: packageName,
protoPath: join(__dirname, 'protobufs/' + protoFileName),
loader: {
arrays: true
}
}
};
}