blob: 78f50756a0601bdd553104c18812999dba7a10ec [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 Meierf8c1c982014-05-28 00:04:32 +020032 .option('--port <port>', 'Set thift server port')
Roger Meier57b354b2014-02-22 01:01:58 +010033 .option('--ssl', 'use ssl transport')
henrique31236232014-02-23 20:16:44 +010034 .option('--promise', 'test with promise style functions')
Roger Meier8909cbd2014-01-26 11:44:27 +010035 .parse(process.argv);
36
Randy Abernethyd60f9782014-03-28 10:36:38 -070037var transport = thrift.TBufferedTransport;
Roger Meier8909cbd2014-01-26 11:44:27 +010038if (program.transport === "framed") {
Randy Abernethyd60f9782014-03-28 10:36:38 -070039 transport = thrift.TFramedTransport;
40}
Roger Meier8909cbd2014-01-26 11:44:27 +010041
Randy Abernethyd60f9782014-03-28 10:36:38 -070042var protocol = thrift.TBinaryProtocol;
43if (program.protocol === "json") {
44 protocol = thrift.TJSONProtocol;
ra20aeba32014-05-11 00:25:01 -070045} else if (program.protocol === "compact") {
46 protocol = thrift.TCompactProtocol;
Randy Abernethyd60f9782014-03-28 10:36:38 -070047}
48
Roger Meierf8c1c982014-05-28 00:04:32 +020049var port = 9090;
50if (String(program.port) === "undefined"){
51} else {
52 port = program.port;
53}
54
Randy Abernethyd60f9782014-03-28 10:36:38 -070055var handler = ThriftTestHandler;
henrique31236232014-02-23 20:16:44 +010056if (program.promise) {
57 handler = ThriftTestHandlerPromise;
Randy Abernethyd60f9782014-03-28 10:36:38 -070058}
henrique31236232014-02-23 20:16:44 +010059
Roger Meier57b354b2014-02-22 01:01:58 +010060var options = {
Roger Meier8909cbd2014-01-26 11:44:27 +010061 protocol: protocol,
62 transport: transport
Roger Meier57b354b2014-02-22 01:01:58 +010063};
Roger Meier57b354b2014-02-22 01:01:58 +010064if (program.ssl) {
Randy Abernethyd60f9782014-03-28 10:36:38 -070065 options.tls = {
66 key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
67 cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
ra779b9ac2014-04-23 20:04:23 -070068 };
Roger Meier57b354b2014-02-22 01:01:58 +010069}
Roger Meierf8c1c982014-05-28 00:04:32 +020070thrift.createServer(ThriftTest, handler, options).listen(port);
Randy Abernethyd60f9782014-03-28 10:36:38 -070071