-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (36 loc) · 1.07 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var PROTO_PATH = __dirname + '/userData.proto';
var grpc = require('grpc');
var protoLoader = require('@grpc/proto-loader');
var packageDefinition = protoLoader.loadSync(
PROTO_PATH,
{keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
});
var user_proto = grpc.loadPackageDefinition(packageDefinition).userData;
/**
* Implements the userDetails RPC method.
*/
function userDetails(call, callback) {
callback(null, {message: 'Name: ' + call.request.name + ' age: ' + call.request.age});
}
/**
* Implements the userDetails Again RPC method.
*/
function userDetailsAgain(call, callback) {
callback(null, {message: 'Last Name: ' + call.request.name});
}
/**
* Starts an RPC server that receives requests for the UserInfo service at the
* sample server port
*/
function main() {
var server = new grpc.Server();
server.addService(user_proto.UserInfo.service,
{userDetails: userDetails, userDetailsAgain: userDetailsAgain});
server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
server.start();
}
main();