ra | a2e4e56 | 2014-03-29 01:14:48 -0700 | [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 server the test.html browser |
Kazuki Matsuda | b909a38 | 2016-02-13 19:36:09 +0900 | [diff] [blame] | 21 | // based JavaScript test page (which must be in the current directory). |
ra | a2e4e56 | 2014-03-29 01:14:48 -0700 | [diff] [blame] | 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). The current directory must also include the browser |
| 26 | // support libraries for test.html (jquery.js, qunit.js and qunit.css |
| 27 | // in ./build/js/lib). |
| 28 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 29 | const fs = require('fs'); |
| 30 | const thrift = require('../../nodejs/lib/thrift'); |
| 31 | const es6Mode = process.argv.includes('--es6'); |
| 32 | const genFolder = es6Mode ? 'gen-nodejs-es6' : 'gen-nodejs'; |
| 33 | const ThriftTestSvc = require(`./${genFolder}/ThriftTest.js`); |
| 34 | const ThriftTestHandler = require('./test_handler').ThriftTestHandler; |
ra | a2e4e56 | 2014-03-29 01:14:48 -0700 | [diff] [blame] | 35 | |
| 36 | //Setup the I/O stack options for the ThriftTest service |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 37 | const ThriftTestSvcOpt = { |
ra | a2e4e56 | 2014-03-29 01:14:48 -0700 | [diff] [blame] | 38 | transport: thrift.TBufferedTransport, |
| 39 | protocol: thrift.TJSONProtocol, |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 40 | processor: ThriftTestSvc, |
| 41 | handler: ThriftTestHandler |
ra | a2e4e56 | 2014-03-29 01:14:48 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 44 | const ThriftWebServerOptions = { |
jfarrell | 2a2b72f | 2018-10-04 23:00:28 -0400 | [diff] [blame] | 45 | files: __dirname, |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 46 | tls: { |
Kazuki Matsuda | b909a38 | 2016-02-13 19:36:09 +0900 | [diff] [blame] | 47 | key: fs.readFileSync('../../../test/keys/server.key'), |
| 48 | cert: fs.readFileSync('../../../test/keys/server.crt') |
| 49 | }, |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 50 | services: { |
Kazuki Matsuda | b909a38 | 2016-02-13 19:36:09 +0900 | [diff] [blame] | 51 | '/service': ThriftTestSvcOpt |
Randy Abernethy | d60f978 | 2014-03-28 10:36:38 -0700 | [diff] [blame] | 52 | } |
ra | a2e4e56 | 2014-03-29 01:14:48 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 55 | const server = thrift.createWebServer(ThriftWebServerOptions); |
| 56 | const port = es6Mode ? 8090 : 8091; |
ra | a2e4e56 | 2014-03-29 01:14:48 -0700 | [diff] [blame] | 57 | server.listen(port); |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 58 | console.log(`Serving files from: ${__dirname}`); |
| 59 | console.log(`Http/Thrift Server (ES6 mode ${es6Mode}) running on port: ${port}`); |