blob: 378a6e2ce8e592ba2e3bf34d3a8628ea943275b0 [file] [log] [blame]
Roger Meier32f39822014-06-18 22:43:17 +02001#!/usr/bin/env nodejs
2
Roger Meier8909cbd2014-01-26 11:44:27 +01003/*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * 'License'); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
Roger Meier57b354b2014-02-22 01:01:58 +010022var fs = require('fs');
23var path = require('path');
Roger Meier8909cbd2014-01-26 11:44:27 +010024var thrift = require('thrift');
Roger Meier8909cbd2014-01-26 11:44:27 +010025var ThriftTest = require('./gen-nodejs/ThriftTest');
26var ThriftTestHandler = require('./test_handler').ThriftTestHandler;
henrique31236232014-02-23 20:16:44 +010027var ThriftTestHandlerPromise = require('./test_handler_promise').ThriftTestHandler;
Roger Meier8909cbd2014-01-26 11:44:27 +010028
Roger Meier8909cbd2014-01-26 11:44:27 +010029var program = require('commander');
30
31program
32 .option('-p, --protocol <protocol>', 'Set thift protocol (binary|json) [protocol]')
33 .option('-t, --transport <transport>', 'Set thift transport (buffered|framed) [transport]')
Roger Meierf8c1c982014-05-28 00:04:32 +020034 .option('--port <port>', 'Set thift server port')
Roger Meier57b354b2014-02-22 01:01:58 +010035 .option('--ssl', 'use ssl transport')
henrique31236232014-02-23 20:16:44 +010036 .option('--promise', 'test with promise style functions')
Roger Meier8909cbd2014-01-26 11:44:27 +010037 .parse(process.argv);
38
Randy Abernethyd60f9782014-03-28 10:36:38 -070039var transport = thrift.TBufferedTransport;
Roger Meier8909cbd2014-01-26 11:44:27 +010040if (program.transport === "framed") {
Randy Abernethyd60f9782014-03-28 10:36:38 -070041 transport = thrift.TFramedTransport;
42}
Roger Meier8909cbd2014-01-26 11:44:27 +010043
Randy Abernethyd60f9782014-03-28 10:36:38 -070044var protocol = thrift.TBinaryProtocol;
45if (program.protocol === "json") {
46 protocol = thrift.TJSONProtocol;
ra20aeba32014-05-11 00:25:01 -070047} else if (program.protocol === "compact") {
48 protocol = thrift.TCompactProtocol;
Randy Abernethyd60f9782014-03-28 10:36:38 -070049}
50
Roger Meierf8c1c982014-05-28 00:04:32 +020051var port = 9090;
52if (String(program.port) === "undefined"){
53} else {
54 port = program.port;
55}
56
Randy Abernethyd60f9782014-03-28 10:36:38 -070057var handler = ThriftTestHandler;
henrique31236232014-02-23 20:16:44 +010058if (program.promise) {
59 handler = ThriftTestHandlerPromise;
Randy Abernethyd60f9782014-03-28 10:36:38 -070060}
henrique31236232014-02-23 20:16:44 +010061
Roger Meier57b354b2014-02-22 01:01:58 +010062var options = {
Roger Meier8909cbd2014-01-26 11:44:27 +010063 protocol: protocol,
64 transport: transport
Roger Meier57b354b2014-02-22 01:01:58 +010065};
Roger Meier57b354b2014-02-22 01:01:58 +010066if (program.ssl) {
Randy Abernethyd60f9782014-03-28 10:36:38 -070067 options.tls = {
68 key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
69 cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
ra779b9ac2014-04-23 20:04:23 -070070 };
Roger Meier57b354b2014-02-22 01:01:58 +010071}
Roger Meierf8c1c982014-05-28 00:04:32 +020072thrift.createServer(ThriftTest, handler, options).listen(port);
Randy Abernethyd60f9782014-03-28 10:36:38 -070073