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 | |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 20 | var fs = require('fs'); |
| 21 | var path = require('path'); |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 22 | var thrift = require('thrift'); |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 23 | var ThriftTest = require('./gen-nodejs/ThriftTest'); |
| 24 | var ThriftTestHandler = require('./test_handler').ThriftTestHandler; |
henrique | 3123623 | 2014-02-23 20:16:44 +0100 | [diff] [blame] | 25 | var ThriftTestHandlerPromise = require('./test_handler_promise').ThriftTestHandler; |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 26 | |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 27 | var program = require('commander'); |
| 28 | |
| 29 | program |
| 30 | .option('-p, --protocol <protocol>', 'Set thift protocol (binary|json) [protocol]') |
| 31 | .option('-t, --transport <transport>', 'Set thift transport (buffered|framed) [transport]') |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 32 | .option('--ssl', 'use ssl transport') |
henrique | 3123623 | 2014-02-23 20:16:44 +0100 | [diff] [blame] | 33 | .option('--promise', 'test with promise style functions') |
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 transport = thrift.TBufferedTransport; |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 37 | if (program.transport === "framed") { |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 38 | transport = thrift.TFramedTransport; |
| 39 | } |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 40 | |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 41 | var protocol = thrift.TBinaryProtocol; |
| 42 | if (program.protocol === "json") { |
| 43 | protocol = thrift.TJSONProtocol; |
| 44 | } |
| 45 | |
| 46 | var handler = ThriftTestHandler; |
henrique | 3123623 | 2014-02-23 20:16:44 +0100 | [diff] [blame] | 47 | if (program.promise) { |
| 48 | handler = ThriftTestHandlerPromise; |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 49 | } |
henrique | 3123623 | 2014-02-23 20:16:44 +0100 | [diff] [blame] | 50 | |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 51 | var options = { |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 52 | protocol: protocol, |
| 53 | transport: transport |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 54 | }; |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 55 | if (program.ssl) { |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 56 | options.tls = { |
| 57 | key: fs.readFileSync(path.resolve(__dirname, 'server.key')), |
| 58 | cert: fs.readFileSync(path.resolve(__dirname, 'server.crt')) |
ra | 779b9ac | 2014-04-23 20:04:23 -0700 | [diff] [blame^] | 59 | }; |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 60 | } |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 61 | thrift.createServer(ThriftTest, handler, options).listen(9090); |
| 62 | |