-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
50 lines (35 loc) · 998 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
rpc.js - Express implementation
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Don't forget to run "npm install" to install express
*/
// include rpc.js
var rpcJs = require('../../rpc.js');
// load your API schema
var rpcJs = rpcJs.gateway({
schema: require('../example.schema.js')
});
// include express
var express = require('express');
var app = module.exports = express.createServer();
// Express Configuration
app.configure(function(){
app.use(express.bodyParser());
app.use(express.errorHandler());
});
// Send html UI
app.get('/help', function(req, res){
res.end(rpcJs.uiHtml());
});
// Send request to rpc.js
app.post('/', function(req, res){
rpcJs.input({
textInput: req.body.rpc,
callback: function(output) {
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify(output));
}
});
});
app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);