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"); |
Cameron Martin | fdaca5e | 2025-01-07 15:25:15 +0000 | [diff] [blame^] | 23 | const { program } = require("commander"); |
Mustafa Senol Cosar | 3f0d444 | 2019-03-01 18:57:09 +0300 | [diff] [blame] | 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 | |
Cameron Martin | fdaca5e | 2025-01-07 15:25:15 +0000 | [diff] [blame^] | 32 | const opts = program.opts(); |
| 33 | const port = opts.port; |
Mustafa Senol Cosar | 3f0d444 | 2019-03-01 18:57:09 +0300 | [diff] [blame] | 34 | |
| 35 | const options = { |
| 36 | transport: thrift.TBufferedTransport, |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 37 | protocol: thrift.TJSONProtocol, |
Mustafa Senol Cosar | 3f0d444 | 2019-03-01 18:57:09 +0300 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | const ServiceHandler = { |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 41 | testEpisode: function (receivedType1Object) { |
Mustafa Senol Cosar | 3f0d444 | 2019-03-01 18:57:09 +0300 | [diff] [blame] | 42 | const type1Object = new Types.Type1(); |
| 43 | type1Object.number = receivedType1Object.number + 1; |
| 44 | type1Object.message = |
| 45 | receivedType1Object.message + " [Hello from the server]"; |
| 46 | return type1Object; |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 47 | }, |
Mustafa Senol Cosar | 3f0d444 | 2019-03-01 18:57:09 +0300 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | const server = thrift.createServer(Service, ServiceHandler, options); |
| 51 | server.listen(port); |