blob: 5af48d9033889de129696e728d062e4084351361 [file] [log] [blame]
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +03001#!/usr/bin/env node
2
3/*
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
22const thrift = require("../../lib/thrift");
Cameron Martinfdaca5e2025-01-07 15:25:15 +000023const { program } = require("commander");
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030024
25program
26 .option("--port <port>", "Set the thrift server port", 9090)
CJCombrink40d3e782026-03-23 06:09:04 +000027 .option("--base <base>", "Set the base: 'pure', 'base' or 'extend'", "pure")
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030028 .parse(process.argv);
29
CJCombrink40d3e782026-03-23 06:09:04 +000030const ServiceBase = require("types-package/first-episode/BaseService");
31const ServicePure = require("./gen-2/second-episode/gen-nodejs/Service");
32const ServiceExtended = require("./gen-2/second-episode/gen-nodejs/ExtendedService");
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030033const Types = require("types-package/first-episode/Types_types");
34
Cameron Martinfdaca5e2025-01-07 15:25:15 +000035const opts = program.opts();
36const port = opts.port;
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030037
CJCombrink40d3e782026-03-23 06:09:04 +000038let Service;
39if (opts.base === "pure") {
40 Service = ServicePure;
41} else if (opts.base === "base") {
42 Service = ServiceBase;
43} else if (opts.base === "extend") {
44 Service = ServiceExtended;
45}
46
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030047const options = {
48 transport: thrift.TBufferedTransport,
Cameron Martincaef0ed2025-01-15 11:58:39 +010049 protocol: thrift.TJSONProtocol,
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030050};
51
52const ServiceHandler = {
Cameron Martincaef0ed2025-01-15 11:58:39 +010053 testEpisode: function (receivedType1Object) {
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030054 const type1Object = new Types.Type1();
55 type1Object.number = receivedType1Object.number + 1;
56 type1Object.message =
57 receivedType1Object.message + " [Hello from the server]";
58 return type1Object;
Cameron Martincaef0ed2025-01-15 11:58:39 +010059 },
CJCombrink40d3e782026-03-23 06:09:04 +000060 testEpisodeExtend: function (receivedType1Object) {
61 const type1Object = new Types.Type1();
62 type1Object.number = receivedType1Object.number + 1;
63 type1Object.message =
64 receivedType1Object.message + " [Hello from the extended server]";
65 return type1Object;
66 },
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030067};
68
69const server = thrift.createServer(Service, ServiceHandler, options);
70server.listen(port);