Mustafa Senol Cosar | 3f0d444 | 2019-03-01 18:57:09 +0300 | [diff] [blame] | 1 | #!/usr/bin/env node |
| 2 | |
| 3 | /* |
| 4 | * Licensed to the Apache Software Foundation (ASF) under one |
| 5 | * or more contributor license agreements. See the NOTICE file |
| 6 | * distributed with this work for additional information |
| 7 | * regarding copyright ownership. The ASF licenses this file |
| 8 | * to you under the Apache License, Version 2.0 (the |
| 9 | * 'License'); you may not use this file except in compliance |
| 10 | * with the License. You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, |
| 15 | * software distributed under the License is distributed on an |
| 16 | * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 17 | * KIND, either express or implied. See the License for the |
| 18 | * specific language governing permissions and limitations |
| 19 | * under the License. |
| 20 | */ |
| 21 | |
| 22 | const thrift = require("../../lib/thrift"); |
| 23 | const program = require("commander"); |
| 24 | |
| 25 | program |
| 26 | .option("--port <port>", "Set the thrift server port", 9090) |
| 27 | .parse(process.argv); |
| 28 | |
| 29 | const Service = require("./gen-2/second-episode/gen-nodejs/Service"); |
| 30 | const Types = require("types-package/first-episode/Types_types"); |
| 31 | |
| 32 | const port = program.port; |
| 33 | |
| 34 | const options = { |
| 35 | transport: thrift.TBufferedTransport, |
| 36 | protocol: thrift.TJSONProtocol |
| 37 | }; |
| 38 | |
| 39 | const ServiceHandler = { |
| 40 | testEpisode: function(receivedType1Object) { |
| 41 | const type1Object = new Types.Type1(); |
| 42 | type1Object.number = receivedType1Object.number + 1; |
| 43 | type1Object.message = |
| 44 | receivedType1Object.message + " [Hello from the server]"; |
| 45 | return type1Object; |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | const server = thrift.createServer(Service, ServiceHandler, options); |
| 50 | server.listen(port); |