-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.js
More file actions
53 lines (37 loc) · 941 Bytes
/
api.js
File metadata and controls
53 lines (37 loc) · 941 Bytes
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
var Hapi = require('hapi');
var server = new Hapi.Server({
connections: {
routes: {
cors: true
}
}
});
var pg = require('pg');
var connectionString = 'postgres://joframart:evgax58@localhost:5432/joframart'
var client = new pg.Client(connectionString);
server.connection({
host: 'localhost',
port: 4000
});
server.route({
method: 'GET',
path: '/sentiment',
handler: function(request, reply)
{
console.log("Responding");
pg.connect(connectionString, function(err, client, done) {
client.query('SELECT * FROM area_sentiment WHERE timestamp_end = $1',
[decodeURI(request.query.time)],
function(err, response){
console.log("response: " + response.rows.length);
if(err) {
return console.error('error running query', err);
}
reply(response.rows);
});
});
}
});
server.start(function () {
console.log('Server running at:', server.info.uri);
});