wilfrem | 2c69b5a | 2015-04-20 19:24:50 +0900 | [diff] [blame] | 1 | import thrift = require("thrift"); |
Cameron Martin | fdaca5e | 2025-01-07 15:25:15 +0000 | [diff] [blame] | 2 | import { program } from 'commander'; |
| 3 | import ThriftTest = require('./gen-nodejs/ThriftTest'); |
| 4 | import test_handler = require('./test_handler'); |
| 5 | |
wilfrem | 2c69b5a | 2015-04-20 19:24:50 +0900 | [diff] [blame] | 6 | |
| 7 | program |
Cameron Martin | fdaca5e | 2025-01-07 15:25:15 +0000 | [diff] [blame] | 8 | .option('--port <port>', 'Set thrift server port', Number.parseInt, 9090) |
| 9 | .option('--promise', 'test with promise style functions') |
| 10 | .option('--protocol', '"Set thrift protocol (binary) [protocol]"') |
wilfrem | 2c69b5a | 2015-04-20 19:24:50 +0900 | [diff] [blame] | 11 | .parse(process.argv); |
| 12 | |
Cameron Martin | fdaca5e | 2025-01-07 15:25:15 +0000 | [diff] [blame] | 13 | var opts = program.opts(); |
| 14 | var port: number = opts.port; |
wilfrem | 2c69b5a | 2015-04-20 19:24:50 +0900 | [diff] [blame] | 15 | |
| 16 | var options: thrift.ServerOptions = { |
| 17 | transport: thrift.TBufferedTransport, |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 18 | protocol: thrift.TBinaryProtocol, |
wilfrem | 2c69b5a | 2015-04-20 19:24:50 +0900 | [diff] [blame] | 19 | }; |
| 20 | |
| 21 | var server: thrift.Server; |
Cameron Martin | fdaca5e | 2025-01-07 15:25:15 +0000 | [diff] [blame] | 22 | if (opts.promise) { |
| 23 | server = thrift.createServer(ThriftTest.Processor, new test_handler.AsyncThriftTestHandler(), options); |
wilfrem | 2c69b5a | 2015-04-20 19:24:50 +0900 | [diff] [blame] | 24 | } else { |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 25 | server = thrift.createServer( |
| 26 | ThriftTest.Processor, |
| 27 | new test_handler.SyncThriftTestHandler(), |
| 28 | options, |
| 29 | ); |
wilfrem | 2c69b5a | 2015-04-20 19:24:50 +0900 | [diff] [blame] | 30 | } |
| 31 | server.listen(port); |