blob: 3519f4af6a880d7ba83bd466b89f925b5625d324 [file] [log] [blame]
ra8f697cb2014-04-23 02:23:18 -07001/*
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
20var fs = require('fs');
21var path = require('path');
22var thrift = require('thrift');
23var ThriftTest = require('./gen-nodejs/ThriftTest');
24var ThriftTestHandler = require('./test_handler').ThriftTestHandler;
25var ThriftTestHandlerPromise = require('./test_handler_promise').ThriftTestHandler;
26
27var 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]')
32 .option('--ssl', 'use ssl transport')
33 .option('--promise', 'test with promise style functions')
34 .parse(process.argv);
35
36var transport = thrift.TBufferedTransport;
37if (program.transport === "framed") {
38 transport = thrift.TFramedTransport;
Randy Abernethy96f4f072015-02-10 02:29:15 -080039}
ra8f697cb2014-04-23 02:23:18 -070040
41var protocol = thrift.TBinaryProtocol;
42if (program.protocol === "json") {
43 protocol = thrift.TJSONProtocol;
Randy Abernethy96f4f072015-02-10 02:29:15 -080044}
ra8f697cb2014-04-23 02:23:18 -070045
46var handler = ThriftTestHandler;
47if (program.promise) {
48 handler = ThriftTestHandlerPromise;
Randy Abernethy96f4f072015-02-10 02:29:15 -080049}
ra8f697cb2014-04-23 02:23:18 -070050
Randy Abernethy96f4f072015-02-10 02:29:15 -080051var SvcOpt = {
52 handler: handler,
53 processor: ThriftTest,
54 protocol: protocol,
55 transport: transport
56};
57var serverOpt = { services: { "/test": SvcOpt } };
ra779b9ac2014-04-23 20:04:23 -070058if (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 Abernethy96f4f072015-02-10 02:29:15 -080064thrift.createWebServer(serverOpt).listen(9090);
ra8f697cb2014-04-23 02:23:18 -070065
66