blob: 6afff0787ed1cc49054c0ab5eeb4ba8ca4530824 [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;
ra20aeba32014-05-11 00:25:01 -070044} else if (program.protocol === "compact") {
45 protocol = thrift.TCompactProtocol;
Randy Abernethyd60f9782014-03-28 10:36:38 -070046}
47
48var handler = ThriftTestHandler;
henrique31236232014-02-23 20:16:44 +010049if (program.promise) {
50 handler = ThriftTestHandlerPromise;
Randy Abernethyd60f9782014-03-28 10:36:38 -070051}
henrique31236232014-02-23 20:16:44 +010052
Roger Meier57b354b2014-02-22 01:01:58 +010053var options = {
Roger Meier8909cbd2014-01-26 11:44:27 +010054 protocol: protocol,
55 transport: transport
Roger Meier57b354b2014-02-22 01:01:58 +010056};
Roger Meier57b354b2014-02-22 01:01:58 +010057if (program.ssl) {
Randy Abernethyd60f9782014-03-28 10:36:38 -070058 options.tls = {
59 key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
60 cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
ra779b9ac2014-04-23 20:04:23 -070061 };
Roger Meier57b354b2014-02-22 01:01:58 +010062}
Randy Abernethyd60f9782014-03-28 10:36:38 -070063thrift.createServer(ThriftTest, handler, options).listen(9090);
64