Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * 'License'); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | var thrift = require('thrift'); |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 20 | |
| 21 | var ThriftTest = require('./gen-nodejs/ThriftTest'), |
| 22 | SecondService = require('./gen-nodejs/SecondService'), |
| 23 | ttypes = require('./gen-nodejs/ThriftTest_types'); |
| 24 | |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 25 | var fs = require("fs"); |
| 26 | var path = require("path"); |
| 27 | |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 28 | var program = require('commander'); |
| 29 | |
| 30 | program |
| 31 | .option('-p, --protocol <protocol>', 'Set thift protocol (binary|json) [protocol]') |
| 32 | .option('-t, --transport <transport>', 'Set thift transport (buffered|framed) [transport]') |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 33 | .option('--ssl', 'use ssl transport') |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 34 | .parse(process.argv); |
| 35 | |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 36 | var protocol = thrift.TBinaryProtocol; |
| 37 | if (program.protocol === "json") { |
| 38 | protocol = thrift.TJSONProtocol; |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 39 | } |
| 40 | |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 41 | var transport = thrift.TBufferedTransport; |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 42 | if (program.transport === "framed") { |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 43 | transport = thrift.TFramedTransport; |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | var ThriftTestHandler = require("./test_handler").ThriftTestHandler; |
| 47 | |
| 48 | var SecondServiceHandler = { |
| 49 | secondtestString: function(thing, result) { |
| 50 | console.log('testString(\'' + thing + '\')'); |
| 51 | result(null, thing); |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | var processor = new thrift.MultiplexedProcessor(); |
| 56 | |
| 57 | processor.registerProcessor( |
| 58 | "ThriftTest", |
| 59 | new ThriftTest.Processor(ThriftTestHandler)); |
| 60 | |
| 61 | processor.registerProcessor( |
| 62 | "SecondService", |
| 63 | new SecondService.Processor(SecondServiceHandler)); |
| 64 | |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 65 | var options = { |
| 66 | transport: transport, |
| 67 | protocol: protocol |
| 68 | }; |
| 69 | |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 70 | if (program.ssl) { |
| 71 | //ssl options |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 72 | options.tls = { |
| 73 | key: fs.readFileSync(path.resolve(__dirname, 'server.key')), |
| 74 | cert: fs.readFileSync(path.resolve(__dirname, 'server.crt')) |
ra | 779b9ac | 2014-04-23 20:04:23 -0700 | [diff] [blame] | 75 | }; |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 76 | } |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 77 | |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 78 | thrift.createMultiplexServer(processor, options).listen(9090); |