blob: 605c700342f4516d08ea8b18ca160fdb22aaf105 [file] [log] [blame]
Roger Meier8909cbd2014-01-26 11:44:27 +01001/*
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 Meier57b354b2014-02-22 01:01:58 +010020var fs = require('fs');
21var path = require('path');
Roger Meier8909cbd2014-01-26 11:44:27 +010022var thrift = require('thrift');
Roger Meier8909cbd2014-01-26 11:44:27 +010023var ThriftTest = require('./gen-nodejs/ThriftTest');
24var ThriftTestHandler = require('./test_handler').ThriftTestHandler;
henrique31236232014-02-23 20:16:44 +010025var ThriftTestHandlerPromise = require('./test_handler_promise').ThriftTestHandler;
Roger Meier8909cbd2014-01-26 11:44:27 +010026
Roger Meier8909cbd2014-01-26 11:44:27 +010027var program = require('commander');
28
29program
30 .option('-p, --protocol <protocol>', 'Set thift protocol (binary|json) [protocol]')
31 .option('-t, --transport <transport>', 'Set thift transport (buffered|framed) [transport]')
Roger Meier57b354b2014-02-22 01:01:58 +010032 .option('--ssl', 'use ssl transport')
henrique31236232014-02-23 20:16:44 +010033 .option('--promise', 'test with promise style functions')
Roger Meier8909cbd2014-01-26 11:44:27 +010034 .parse(process.argv);
35
Randy Abernethyd60f9782014-03-28 10:36:38 -070036var transport = thrift.TBufferedTransport;
Roger Meier8909cbd2014-01-26 11:44:27 +010037if (program.transport === "framed") {
Randy Abernethyd60f9782014-03-28 10:36:38 -070038 transport = thrift.TFramedTransport;
39}
Roger Meier8909cbd2014-01-26 11:44:27 +010040
Randy Abernethyd60f9782014-03-28 10:36:38 -070041var protocol = thrift.TBinaryProtocol;
42if (program.protocol === "json") {
43 protocol = thrift.TJSONProtocol;
44}
45
46var handler = ThriftTestHandler;
henrique31236232014-02-23 20:16:44 +010047if (program.promise) {
48 handler = ThriftTestHandlerPromise;
Randy Abernethyd60f9782014-03-28 10:36:38 -070049}
henrique31236232014-02-23 20:16:44 +010050
Roger Meier57b354b2014-02-22 01:01:58 +010051var options = {
Roger Meier8909cbd2014-01-26 11:44:27 +010052 protocol: protocol,
53 transport: transport
Roger Meier57b354b2014-02-22 01:01:58 +010054};
Roger Meier57b354b2014-02-22 01:01:58 +010055if (program.ssl) {
Randy Abernethyd60f9782014-03-28 10:36:38 -070056 options.tls = {
57 key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
58 cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
ra779b9ac2014-04-23 20:04:23 -070059 };
Roger Meier57b354b2014-02-22 01:01:58 +010060}
Randy Abernethyd60f9782014-03-28 10:36:38 -070061thrift.createServer(ThriftTest, handler, options).listen(9090);
62