-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
37 lines (33 loc) · 1.14 KB
/
app.js
File metadata and controls
37 lines (33 loc) · 1.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
var restify = require('restify'),
port = process.env.PORT || 3000,
server = restify.createServer(),
cassandraOpts = require('./cassandra_defaults.json'),
routePrefix = '/v1',
cassandra = require('cassandra-driver'),
cassandraClient = new cassandra.Client({ contactPoints: cassandraOpts.remote.hostIps, keyspace: cassandraOpts.remote.keyspace}),
query;
server.get('/echo', function (req, res, next) {
res.send('hello world 2');
next();
});
server.get({path: routePrefix + '/accounts', flags: 'i'}, getAccounts);
function getAccounts(req, res, next) {
query = 'select * from accounts';
cassandraClient.execute(query, [], function(err, result) {
var accounts = [];
if (err) {
console.log(err);
throw(err);
} else {
for (var i=0; i < result.rowLength; i++) {
accounts.push(result.rows[i]);
}
res.send(accounts);
next();
}
});
}
server.listen(port, function() {
var msg = 'Starting service using port \'' + port + '\' and environment \'' + process.env.NODE_ENV + '\'';
console.log(msg);
});