murgatroid99 | e89af55 | 2015-02-19 13:33:04 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2015 gRPC authors. |
murgatroid99 | e89af55 | 2015-02-19 13:33:04 -0800 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
murgatroid99 | e89af55 | 2015-02-19 13:33:04 -0800 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
murgatroid99 | e89af55 | 2015-02-19 13:33:04 -0800 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
murgatroid99 | e89af55 | 2015-02-19 13:33:04 -0800 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
murgatroid99 | ddc0eb1 | 2016-05-04 10:27:12 -0700 | [diff] [blame] | 19 | var PROTO_PATH = __dirname + '/../../protos/helloworld.proto'; |
murgatroid99 | 4c8f8d8 | 2016-02-26 11:43:05 -0800 | [diff] [blame] | 20 | |
murgatroid99 | c7edb0e | 2016-04-29 15:33:31 -0700 | [diff] [blame] | 21 | var grpc = require('grpc'); |
| 22 | var hello_proto = grpc.load(PROTO_PATH).helloworld; |
murgatroid99 | e89af55 | 2015-02-19 13:33:04 -0800 | [diff] [blame] | 23 | |
murgatroid99 | e89af55 | 2015-02-19 13:33:04 -0800 | [diff] [blame] | 24 | /** |
Yang Gao | 600d70c | 2015-02-20 10:50:46 -0800 | [diff] [blame] | 25 | * Implements the SayHello RPC method. |
murgatroid99 | e89af55 | 2015-02-19 13:33:04 -0800 | [diff] [blame] | 26 | */ |
Yang Gao | 3440548 | 2015-02-20 11:35:20 -0800 | [diff] [blame] | 27 | function sayHello(call, callback) { |
murgatroid99 | c7edb0e | 2016-04-29 15:33:31 -0700 | [diff] [blame] | 28 | callback(null, {message: 'Hello ' + call.request.name}); |
murgatroid99 | e89af55 | 2015-02-19 13:33:04 -0800 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Starts an RPC server that receives requests for the Greeter service at the |
| 33 | * sample server port |
| 34 | */ |
| 35 | function main() { |
murgatroid99 | c919228 | 2015-08-28 15:24:07 -0700 | [diff] [blame] | 36 | var server = new grpc.Server(); |
Florian Nagel | a36b429 | 2017-10-03 15:21:14 +0200 | [diff] [blame^] | 37 | server.addService(hello_proto.Greeter.service, {sayHello: sayHello}); |
murgatroid99 | c919228 | 2015-08-28 15:24:07 -0700 | [diff] [blame] | 38 | server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure()); |
| 39 | server.start(); |
murgatroid99 | e89af55 | 2015-02-19 13:33:04 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | main(); |