blob: 90634c9555efdeae4d013388744b1a5c16218f61 [file] [log] [blame]
Henrique Mendonçaa9e62482013-09-20 16:47:02 +02001/*
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 */
19var thrift = require('thrift');
20var TBufferedTransport = require('thrift/transport').TBufferedTransport;
21var TJSONProtocol = require('thrift/protocol').TJSONProtocol;
22var HelloSvc = require('./gen-nodejs/HelloSvc.js');
23var TimesTwoSvc = require('./gen-nodejs/TimesTwo.js');
24
25var helloHandler = {
26 hello_func: function(result) {
27 this.call_counter = this.call_counter || 0;
28 console.log("Client call: " + (++this.call_counter));
29 result(null, "Hello Apache Thrift for JavaScript " + this.call_counter);
30 }
31}
32
33var timesTwoHandler = {
34 dbl: function(val, result) {
35 console.log("Client call: " + val);
36 result(null, val * 2);
37 }
38}
39
40var helloService = {
41 transport: TBufferedTransport,
42 protocol: TJSONProtocol,
43 cls: HelloSvc,
44 handler: helloHandler
45};
46
47var dblService = {
48 transport: TBufferedTransport,
49 protocol: TJSONProtocol,
50 cls: TimesTwoSvc,
51 handler: timesTwoHandler
52};
53
54var StaticHttpThriftServerOptions = {
55 staticFilePath: ".",
56 services: {
57 "/hello": helloService,
58 "/dbl": dblService,
59 }
60}
61
62var server = thrift.createStaticHttpThriftServer(StaticHttpThriftServerOptions);
63var port = 8585;
64server.listen(port);
65console.log("Http/Thrift Server running on port: " + port);