import grpc from '@grpc/grpc-js'; import { loadSync } from '@grpc/proto-loader'; import type { ServerUnaryCall, sendUnaryData } from '@grpc/grpc-js'; type Empty = { } type Task = { id: number, title: string } type TaskList = { tasks: Task[] } const tasks: Task[] = [ { id: 1, title: 'Tarefa 01'}, { id: 2, title: 'Tarefa 02'}, { id: 3, title: 'Tarefa 03'}, { id: 4, title: 'Tarefa 04'} ] const { Server, ServerCredentials } = grpc as any; const taskDef = loadSync('./tasks.proto'); const taskProto = (grpc.loadPackageDefinition as any)(taskDef).task as any; const server = new Server(); server.addService(taskProto.TaskService.service, { FindAll: (_: ServerUnaryCall, callback: sendUnaryData) => { callback(null, { tasks }) } }); server.bindAsync('0.0.0.0:5050', ServerCredentials.createInsecure(), () => { console.log("Servidor rodando na porta 5000") })