blob: 7e78d9edaf9504281df8bfbb3d4b3c78d414bc02 [file] [log] [blame]
raa2e4e562014-03-29 01:14:48 -07001/*
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 Matsudab909a382016-02-13 19:36:09 +090021// based JavaScript test page (which must be in the current directory).
raa2e4e562014-03-29 01:14:48 -070022// 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
Kazuki Matsudab909a382016-02-13 19:36:09 +090029var fs = require('fs');
raa2e4e562014-03-29 01:14:48 -070030var thrift = require('../../nodejs/lib/thrift');
31var ThriftTestSvc = require('./gen-nodejs/ThriftTest.js');
32var ThriftTestHandler = require('./test_handler').ThriftTestHandler;
33
34//Setup the I/O stack options for the ThriftTest service
35var ThriftTestSvcOpt = {
36 transport: thrift.TBufferedTransport,
37 protocol: thrift.TJSONProtocol,
Randy Abernethyd60f9782014-03-28 10:36:38 -070038 processor: ThriftTestSvc,
39 handler: ThriftTestHandler
raa2e4e562014-03-29 01:14:48 -070040};
41
42var ThriftWebServerOptions = {
Kazuki Matsudab909a382016-02-13 19:36:09 +090043 files: '.',
Randy Abernethyd60f9782014-03-28 10:36:38 -070044 tls: {
Kazuki Matsudab909a382016-02-13 19:36:09 +090045 key: fs.readFileSync('../../../test/keys/server.key'),
46 cert: fs.readFileSync('../../../test/keys/server.crt')
47 },
Randy Abernethyd60f9782014-03-28 10:36:38 -070048 services: {
Kazuki Matsudab909a382016-02-13 19:36:09 +090049 '/service': ThriftTestSvcOpt
Randy Abernethyd60f9782014-03-28 10:36:38 -070050 }
raa2e4e562014-03-29 01:14:48 -070051};
52
53var server = thrift.createWebServer(ThriftWebServerOptions);
54var port = 8089;
55server.listen(port);
Kazuki Matsudab909a382016-02-13 19:36:09 +090056console.log('Serving files from: ' + __dirname);
57console.log('Http/Thrift Server running on port: ' + port);