Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ function loadObject(reflectionObject)
Returns the same structure that `load` returns, but takes a reflection object from `ProtoBuf.js` instead of a file name.

```javascript
function buildServer(serviceArray)
function Server([serverOpions])
```

Takes an array of service objects and returns a constructor for a server that handles requests to all of those services.
Constructs a server to which service/implementation pairs can be added.


```javascript
Expand Down
18 changes: 7 additions & 11 deletions src/node/examples/math_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
var grpc = require('..');
var math = grpc.load(__dirname + '/math.proto').math;

var Server = grpc.buildServer([math.Math.service]);

/**
* Server function for division. Provides the /Math/DivMany and /Math/Div
* functions (Div is just DivMany with only one stream element). For each
Expand Down Expand Up @@ -108,19 +106,17 @@ function mathDivMany(stream) {
stream.end();
});
}

var server = new Server({
'math.Math' : {
div: mathDiv,
fib: mathFib,
sum: mathSum,
divMany: mathDivMany
}
var server = new grpc.Server();
server.addProtoService(math.Math.service, {
div: mathDiv,
fib: mathFib,
sum: mathSum,
divMany: mathDivMany
});

if (require.main === module) {
server.bind('0.0.0.0:50051');
server.listen();
server.start();
}

/**
Expand Down
16 changes: 7 additions & 9 deletions src/node/examples/route_guide_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ var _ = require('lodash');
var grpc = require('..');
var examples = grpc.load(__dirname + '/route_guide.proto').examples;

var Server = grpc.buildServer([examples.RouteGuide.service]);

var COORD_FACTOR = 1e7;

/**
Expand Down Expand Up @@ -228,14 +226,14 @@ function routeChat(call) {
* @return {Server} The new server object
*/
function getServer() {
return new Server({
'examples.RouteGuide' : {
getFeature: getFeature,
listFeatures: listFeatures,
recordRoute: recordRoute,
routeChat: routeChat
}
var server = new grpc.Server();
server.addProtoService(examples.RouteGuide.service, {
getFeature: getFeature,
listFeatures: listFeatures,
recordRoute: recordRoute,
routeChat: routeChat
});
return server;
}

if (require.main === module) {
Expand Down
15 changes: 6 additions & 9 deletions src/node/examples/stock_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ var _ = require('lodash');
var grpc = require('..');
var examples = grpc.load(__dirname + '/stock.proto').examples;

var StockServer = grpc.buildServer([examples.Stock.service]);

function getLastTradePrice(call, callback) {
callback(null, {symbol: call.request.symbol, price: 88});
}
Expand Down Expand Up @@ -73,13 +71,12 @@ function getLastTradePriceMultiple(call) {
});
}

var stockServer = new StockServer({
'examples.Stock' : {
getLastTradePrice: getLastTradePrice,
getLastTradePriceMultiple: getLastTradePriceMultiple,
watchFutureTrades: watchFutureTrades,
getHighestTradePrice: getHighestTradePrice
}
var stockServer = new grpc.Server();
stockServer.addProtoService(examples.Stock.service, {
getLastTradePrice: getLastTradePrice,
getLastTradePriceMultiple: getLastTradePriceMultiple,
watchFutureTrades: watchFutureTrades,
getHighestTradePrice: getHighestTradePrice
});

if (require.main === module) {
Expand Down
6 changes: 2 additions & 4 deletions src/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ exports.loadObject = loadObject;
exports.load = load;

/**
* See docs for server.makeServerConstructor
* See docs for Server
*/
exports.buildServer = server.makeProtobufServerConstructor;
exports.Server = server.Server;

/**
* Status name to code number mapping
Expand All @@ -159,5 +159,3 @@ exports.ServerCredentials = grpc.ServerCredentials;
exports.getGoogleAuthDelegate = getGoogleAuthDelegate;

exports.makeGenericClientConstructor = client.makeClientConstructor;

exports.makeGenericServerConstructor = server.makeServerConstructor;
20 changes: 9 additions & 11 deletions src/node/interop/interop_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ var path = require('path');
var _ = require('lodash');
var grpc = require('..');
var testProto = grpc.load(__dirname + '/test.proto').grpc.testing;
var Server = grpc.buildServer([testProto.TestService.service]);

/**
* Create a buffer filled with size zeroes
Expand Down Expand Up @@ -173,16 +172,15 @@ function getServer(port, tls) {
key_data,
pem_data);
}
var server = new Server({
'grpc.testing.TestService' : {
emptyCall: handleEmpty,
unaryCall: handleUnary,
streamingOutputCall: handleStreamingOutput,
streamingInputCall: handleStreamingInput,
fullDuplexCall: handleFullDuplex,
halfDuplexCall: handleHalfDuplex
}
}, null, options);
var server = new grpc.Server(options);
server.addProtoService(testProto.TestService.service, {
emptyCall: handleEmpty,
unaryCall: handleUnary,
streamingOutputCall: handleStreamingOutput,
streamingInputCall: handleStreamingInput,
fullDuplexCall: handleFullDuplex,
halfDuplexCall: handleHalfDuplex
});
var port_num = server.bind('0.0.0.0:' + port, server_creds);
return {server: server, port: port_num};
}
Expand Down
Loading