-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
223 lines (202 loc) · 6.14 KB
/
server.js
File metadata and controls
223 lines (202 loc) · 6.14 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
'use strict';
const path = require('path')
const Hapi = require('hapi');
const Vision = require('vision')
const Inert = require('inert')
const utils = require('./utils.js')
const ripple = new utils()
// Create a server with a host and port
const server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 8000
});
server.register([{
register: Vision // add template rendering support in hapi
}, {
register: Inert // handle static files and directories in hapi
}
], function (err) {
if (err) {
throw err
}
server.views({
engines: { html: require('handlebars') },
path: path.join(__dirname, '/templates'),
layout: true,
partialsPath: path.join(__dirname, '/templates/partials'),
helpersPath: path.join(__dirname, '/templates/helpers'),
compileMode: 'sync',
isCached: 'false' // set to true in production
});
});
server.route({
path: '/static/{path*}',
method: 'GET',
handler: {
directory: {
path: [path.join(__dirname, '/node_modules/bootstrap/dist'), path.join(__dirname, '/node_modules/font-awesome'), path.join(__dirname, '/templates/static')],
listing: false,
index: false
}
}
});
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
var path = request.url.path.replace(/^\/|\/$/g, '') // remove leading and trailing slashes from the string
reply.view('index', { title: 'The Invested Researcher | BlockHack 2016',
path: path })
}
});
server.route({
method: 'GET',
path: '/main',
handler: function (request, reply) {
var path = request.url.path.replace(/^\/|\/$/g, '') // remove leading and trailing slashes from the string
reply.view('main', { title: 'The Invested Researcher | BlockHack 2016',
path: path })
}
});
server.route({
method: 'GET',
path: '/search',
handler: function (request, reply) {
var path = request.url.path.replace(/^\/|\/$/g, '') // remove leading and trailing slashes from the string
reply.view('search', { title: 'The Invested Researcher | BlockHack 2016',
path: path })
}
});
server.route({
method: 'GET',
path: '/invest',
handler: function (request, reply) {
var path = request.url.path.replace(/^\/|\/$/g, '') // remove leading and trailing slashes from the string
reply.view('invest', { title: 'The Invested Researcher | BlockHack 2016',
path: path })
}
});
server.route({
method: 'GET',
path: '/research',
handler: function (request, reply) {
var path = request.url.path.replace(/^\/|\/$/g, '') // remove leading and trailing slashes from the string
reply.view('research', { title: 'The Invested Researcher | BlockHack 2016',
path: path })
}
});
server.route({
method: 'GET',
path: '/project',
handler: function (request, reply) {
ripple.get_orders('LCR', 'AUD')
.then((orders) => {
var path = request.url.path.replace(/^\/|\/$/g, '') // remove leading and trailing slashes from the string
reply.view('cancerResearch', { title: 'The Invested Researcher | BlockHack 2016',
path: path, orders: orders })
});
}
});
server.route({
method: 'GET',
path: '/investor',
handler: function (request, reply) {
ripple.get_investor_balances('Inv1')
.then((balances) => {
var i1fb = balances.funds[0].balance
var i1fh = balances.investments[0].holding
var path = request.url.path.replace(/^\/|\/$/g, '') // remove leading and trailing slashes from the string
reply.view('investor', { title: 'The Invested Researcher | BlockHack 2016',
path: path, balances: balances, i1fb: i1fb, i1fh: i1fh })
});
}
});
server.route({
method: 'GET',
path: '/lcr',
handler: function (request, reply) {
var account_id = 'rsrTVFtfuS9BAbUYknHAtM399bg8bPpwzt'
var path = request.url.path.replace(/^\/|\/$/g, '') // remove leading and trailing slashes from the string
Ripple.getBalances(account_id).then(function (balances) {
reply.view('lcr', { title: 'The Invested Researcher | BlockHack 2016',
path: path, balances: (balances) })
})
}
});
server.route({
method: 'GET',
path: '/signup',
handler: function (request, reply) {
var path = request.url.path.replace(/^\/|\/$/g, '') // remove leading and trailing slashes from the string
reply.view('signup', { title: 'The Invested Researcher | BlockHack 2016',
path: path })
}
});
server.route({
method: 'GET',
path: '/login',
handler: function (request, reply) {
var path = request.url.path.replace(/^\/|\/$/g, '') // remove leading and trailing slashes from the string
reply.view('login', { title: 'The Invested Researcher | BlockHack 2016',
path: path })
}
});
// Start the server
ripple.init()
.then(() => {
server.start((err) => {
if (err) {
throw err;
}
console.log('Server running at:', server.info.uri);
});
})
// ripple.init()
// .then(() => {
// ripple.get_investor_balances('Inv1').then(function (balances) {
// // console.log(balances)
// console.log(balances)
// console.log(balances)
// var i1fb = balances.funds[0].balance
// var i1fh = balances.investments[0].holding
// console.log(i1fb)
// console.log(i1fh)
// })
// })
// .then(() => {
// ripple.get_investor_balances('Inv2').then(function (balances) {
// // console.log(balances)
// console.log(balances)
// console.log(balances)
// var i2fb = balances.funds[0].balance
// console.log(i2fb)
// })
// })
// .then(() => {
// ripple.get_investor_balances('Inv3').then(function (balances) {
// // console.log(balances)
// console.log(balances)
// console.log(balances)
// var i3fb = balances.funds[0].balance
// console.log(i3fb)
// })
// })
// .then(() => {
// ripple.get_project_balances('Res1').then(function (balances) {
// console.log(balances)
// console.log(balances.funds)
// })
// })
// .then(() => {
// ripple.get_project_balances('Res2').then(function (balances) {
// console.log(balances)
// console.log(balances.funds)
// })
// })
// .then(() => {
// ripple.get_project_balances('Res3').then(function (balances) {
// console.log(balances)
// console.log(balances.funds)
// })
// })