Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 1 | /* |
| 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 | |
| 20 | // This HTTP server is designed to serve the test.html browser |
| 21 | // based JavaScript test page (which must be in the current directory). |
| 22 | // This server also supplies the Thrift based test service, which depends |
| 23 | // on the standard ThriftTest.thrift IDL service (which must be compiled |
| 24 | // for Node and browser based JavaScript in ./gen-nodejs and ./gen-js |
| 25 | // respectively). |
| 26 | // |
| 27 | // Using the command flag --es6, this server can be run using nodejs code built |
| 28 | // for the es6 environment or for pre-es6 environment. |
| 29 | // |
| 30 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 31 | const thrift = require("../../nodejs/lib/thrift"); |
| 32 | const es6Mode = process.argv.includes("--es6"); |
| 33 | const genFolder = es6Mode ? "gen-nodejs-es6" : "gen-nodejs"; |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 34 | const ThriftTestSvc = require(`./${genFolder}/ThriftTest.js`); |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 35 | const ThriftTestHandler = require("./test_handler").ThriftTestHandler; |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 36 | |
| 37 | const ThriftTestSvcOpt = { |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 38 | transport: thrift.TBufferedTransport, |
| 39 | protocol: thrift.TJSONProtocol, |
| 40 | processor: ThriftTestSvc, |
| 41 | handler: ThriftTestHandler, |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | const ThriftWebServerOptions = { |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 45 | files: __dirname, |
| 46 | services: { |
| 47 | "/service": ThriftTestSvcOpt, |
| 48 | }, |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | const server = thrift.createWebServer(ThriftWebServerOptions); |
| 52 | const port = es6Mode ? 8088 : 8089; |
| 53 | server.listen(port); |
| 54 | console.log(`Serving files from: ${__dirname}`); |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 55 | console.log( |
| 56 | `Http/Thrift Server (ES6 mode ${es6Mode}) running on port: ${port}`, |
| 57 | ); |