27 lines
798 B
TypeScript
27 lines
798 B
TypeScript
import { INestApplication } from '@nestjs/common'
|
|
import { ConfigService } from '@nestjs/config'
|
|
import { MicroserviceOptions, Transport } from '@nestjs/microservices'
|
|
import { PROTO_PATHS } from '@teacinema/contracts'
|
|
|
|
export function setupGrpc(app: INestApplication, config: ConfigService) {
|
|
const host = config.getOrThrow<string>('GRPC_HOST')
|
|
const port = config.getOrThrow<string>('GRPC_PORT')
|
|
const url = `${host}:${port}`
|
|
|
|
app.connectMicroservice<MicroserviceOptions>({
|
|
transport: Transport.GRPC,
|
|
options: {
|
|
url,
|
|
package: ['movie.v1', 'category.v1'],
|
|
protoPath: [PROTO_PATHS.MOVIE, PROTO_PATHS.CATEGORY],
|
|
loader: {
|
|
keepCase: false,
|
|
longs: String,
|
|
enums: String,
|
|
defaults: true,
|
|
oneofs: true
|
|
}
|
|
}
|
|
})
|
|
}
|