add reflection service to valut
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
import { Server, ServerUnaryCall, sendUnaryData } from '@grpc/grpc-js'
|
||||
import {
|
||||
Server,
|
||||
ServerUnaryCall,
|
||||
sendUnaryData,
|
||||
loadPackageDefinition,
|
||||
} from '@grpc/grpc-js'
|
||||
import { ReflectionService } from '@grpc/reflection'
|
||||
import { loadSync } from '@grpc/proto-loader'
|
||||
|
||||
import {
|
||||
Character,
|
||||
@@ -6,35 +13,45 @@ import {
|
||||
CreateCharacterRequest,
|
||||
} from './proto/character'
|
||||
|
||||
import { characterManagerDefinition } from "./proto/character.grpc-server"
|
||||
import { characterManagerDefinition } from './proto/character.grpc-server'
|
||||
|
||||
export function initCharacterService(server: Server) {
|
||||
server.addService(characterManagerDefinition, {
|
||||
createCharacter: createCharacter_Call,
|
||||
getCharacter: getCharacter_Call,
|
||||
})
|
||||
|
||||
new ReflectionService(loadSync('./src/proto/character.proto')).addToServer(
|
||||
server,
|
||||
)
|
||||
}
|
||||
|
||||
function createCharacter_Call(call: ServerUnaryCall<CreateCharacterRequest, Character>, callback: sendUnaryData<Character>) {
|
||||
function createCharacter_Call(
|
||||
call: ServerUnaryCall<CreateCharacterRequest, Character>,
|
||||
callback: sendUnaryData<Character>,
|
||||
) {
|
||||
callback(null, createCharacter(call.request))
|
||||
}
|
||||
|
||||
function createCharacter(request: CreateCharacterRequest): Character {
|
||||
return {
|
||||
playerName: "test player",
|
||||
characterName: "test character",
|
||||
characterAlias: ["test alias"]
|
||||
return {
|
||||
playerName: 'test player',
|
||||
characterName: 'test character',
|
||||
characterAlias: ['test alias'],
|
||||
}
|
||||
}
|
||||
|
||||
function getCharacter_Call(call: ServerUnaryCall<GetCharacterRequest, Character>, callback: sendUnaryData<Character>) {
|
||||
function getCharacter_Call(
|
||||
call: ServerUnaryCall<GetCharacterRequest, Character>,
|
||||
callback: sendUnaryData<Character>,
|
||||
) {
|
||||
callback(null, getCharacter(call.request))
|
||||
}
|
||||
|
||||
function getCharacter(request: GetCharacterRequest): Character {
|
||||
return {
|
||||
playerName: "test player",
|
||||
characterName: "test character",
|
||||
characterAlias: ["test alias"]
|
||||
playerName: 'test player',
|
||||
characterName: 'test character',
|
||||
characterAlias: ['test alias'],
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user