auth/src/main.ts

43 lines
1.3 KiB
TypeScript

import { NestFactory } from '@nestjs/core';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { join } from 'path';
import { AppModule } from './app.module';
import {
GRPC_AUTHENTICATION_PACKAGE_NAME,
GRPC_AUTHORIZATION_PACKAGE_NAME,
GRPC_HEALTH_PACKAGE_NAME,
} from './app.constants';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.connectMicroservice<MicroserviceOptions>({
transport: Transport.TCP,
});
app.connectMicroservice<MicroserviceOptions>({
transport: Transport.GRPC,
options: {
package: [
GRPC_AUTHENTICATION_PACKAGE_NAME,
GRPC_AUTHORIZATION_PACKAGE_NAME,
GRPC_HEALTH_PACKAGE_NAME,
],
protoPath: [
join(
__dirname,
'modules/authentication/interface/grpc-controllers/authentication.proto',
),
join(
__dirname,
'modules/authorization/interface/grpc-controllers/authorization.proto',
),
join(__dirname, 'health.proto'),
],
url: `${process.env.SERVICE_URL}:${process.env.SERVICE_PORT}`,
loader: { keepCase: true, enums: String },
},
});
await app.startAllMicroservices();
await app.listen(process.env.HEALTH_SERVICE_PORT as unknown as number);
}
bootstrap();