-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
47 lines (31 loc) · 830 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
/*
rpc.js - Flatiron implementation
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Don't forget to run "npm install" to install Flatiron
*/
// Flatiron
var flatiron = require('flatiron'),
app = flatiron.app;
app.use(flatiron.plugins.http);
// Load rpc.js
var rpc = require('../../rpc.js');
// Setup your schema
var rpcJs = rpc.gateway({
schema: require('../example.schema.js')
});
// Serv UI static file
app.router.get('/help', function () {
this.res.end( rpcJs.uiHtml() );
});
app.router.post('/', function () {
var flatiron = this;
// Send request to rpc.js
rpcJs.input({
textInput: flatiron.req.body.rpc,
callback: function(output) {
flatiron.res.writeHead(200, {'Content-Type': 'application/json'});
flatiron.res.end(JSON.stringify(output));
}
});
});
app.start(3000);