ra | 8f697cb | 2014-04-23 02:23:18 -0700 | [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 | |
| 20 | var fs = require('fs'); |
| 21 | var path = require('path'); |
| 22 | var thrift = require('thrift'); |
| 23 | var ThriftTest = require('./gen-nodejs/ThriftTest'); |
| 24 | var ThriftTestHandler = require('./test_handler').ThriftTestHandler; |
| 25 | var ThriftTestHandlerPromise = require('./test_handler_promise').ThriftTestHandler; |
| 26 | |
| 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]') |
| 32 | .option('--ssl', 'use ssl transport') |
| 33 | .option('--promise', 'test with promise style functions') |
| 34 | .parse(process.argv); |
| 35 | |
| 36 | var transport = thrift.TBufferedTransport; |
| 37 | if (program.transport === "framed") { |
| 38 | transport = thrift.TFramedTransport; |
Randy Abernethy | 96f4f07 | 2015-02-10 02:29:15 -0800 | [diff] [blame] | 39 | } |
ra | 8f697cb | 2014-04-23 02:23:18 -0700 | [diff] [blame] | 40 | |
| 41 | var protocol = thrift.TBinaryProtocol; |
| 42 | if (program.protocol === "json") { |
| 43 | protocol = thrift.TJSONProtocol; |
Randy Abernethy | 96f4f07 | 2015-02-10 02:29:15 -0800 | [diff] [blame] | 44 | } |
ra | 8f697cb | 2014-04-23 02:23:18 -0700 | [diff] [blame] | 45 | |
| 46 | var handler = ThriftTestHandler; |
| 47 | if (program.promise) { |
| 48 | handler = ThriftTestHandlerPromise; |
Randy Abernethy | 96f4f07 | 2015-02-10 02:29:15 -0800 | [diff] [blame] | 49 | } |
ra | 8f697cb | 2014-04-23 02:23:18 -0700 | [diff] [blame] | 50 | |
Randy Abernethy | 96f4f07 | 2015-02-10 02:29:15 -0800 | [diff] [blame] | 51 | var SvcOpt = { |
| 52 | handler: handler, |
| 53 | processor: ThriftTest, |
| 54 | protocol: protocol, |
| 55 | transport: transport |
| 56 | }; |
| 57 | var serverOpt = { services: { "/test": SvcOpt } }; |
ra | 779b9ac | 2014-04-23 20:04:23 -0700 | [diff] [blame] | 58 | if (program.ssl) { |
| 59 | serverOpt.tls = { |
| 60 | key: fs.readFileSync(path.resolve(__dirname, 'server.key')), |
| 61 | cert: fs.readFileSync(path.resolve(__dirname, 'server.crt')) |
| 62 | }; |
| 63 | } |
Randy Abernethy | 96f4f07 | 2015-02-10 02:29:15 -0800 | [diff] [blame] | 64 | thrift.createWebServer(serverOpt).listen(9090); |
ra | 8f697cb | 2014-04-23 02:23:18 -0700 | [diff] [blame] | 65 | |
| 66 | |