| 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 |
| CJCombrink | dfeab8d | 2026-03-06 07:03:56 +0100 | [diff] [blame^] | 8 | .option('--port <port>', 'Set thrift server port', (v) => parseInt(v, 10), 9090) |
| Cameron Martin | fdaca5e | 2025-01-07 15:25:15 +0000 | [diff] [blame] | 9 | .option('--promise', 'test with promise style functions') |
| CJCombrink | dfeab8d | 2026-03-06 07:03:56 +0100 | [diff] [blame^] | 10 | .option('--protocol <protocol>', '"Set thrift protocol (binary) [protocol]"') |
| 11 | .option('--transport <transport>', '"Set thrift transport (buffered) [transport]"') |
| wilfrem | 2c69b5a | 2015-04-20 19:24:50 +0900 | [diff] [blame] | 12 | .parse(process.argv); |
| 13 | |
| Cameron Martin | fdaca5e | 2025-01-07 15:25:15 +0000 | [diff] [blame] | 14 | var opts = program.opts(); |
| 15 | var port: number = opts.port; |
| wilfrem | 2c69b5a | 2015-04-20 19:24:50 +0900 | [diff] [blame] | 16 | |
| 17 | var options: thrift.ServerOptions = { |
| 18 | transport: thrift.TBufferedTransport, |
| Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 19 | protocol: thrift.TBinaryProtocol, |
| wilfrem | 2c69b5a | 2015-04-20 19:24:50 +0900 | [diff] [blame] | 20 | }; |
| 21 | |
| 22 | var server: thrift.Server; |
| Cameron Martin | fdaca5e | 2025-01-07 15:25:15 +0000 | [diff] [blame] | 23 | if (opts.promise) { |
| 24 | server = thrift.createServer(ThriftTest.Processor, new test_handler.AsyncThriftTestHandler(), options); |
| wilfrem | 2c69b5a | 2015-04-20 19:24:50 +0900 | [diff] [blame] | 25 | } else { |
| Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 26 | server = thrift.createServer( |
| 27 | ThriftTest.Processor, |
| 28 | new test_handler.SyncThriftTestHandler(), |
| 29 | options, |
| 30 | ); |
| wilfrem | 2c69b5a | 2015-04-20 19:24:50 +0900 | [diff] [blame] | 31 | } |
| 32 | server.listen(port); |