-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.js
67 lines (55 loc) · 1.63 KB
/
web.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var express = require('express');
var app = express.createServer(express.logger());
app.use(express.bodyParser());
var pg = require('pg');
app.get('/', function(request, response) {
response.send('Hello World!');
});
app.get('/user', function(request, response){
pg.connect(process.env.DATABASE_URL, function(err, client) {
var query = client.query('SELECT * from users')
query.on('row', function(result)
{
response.send(result);
});
});
});
app.post('/users/login', function(request, response){
console.log("body"+request.body+"\n");
var data = request.body;
pg.connect(process.env.DATABASE_URL, function(err, client) {
response.send("password is"+data.password+"\n");
var query = client.query('SELECT count FROM users u WHERE u.password = ' + data.password + ' and u.name = ' + data.user);
var returnDict = {};
query.on('row', function(result)
{
response.send("result is"+result+"\n")
//response.send("test\n"+console.dir(result));
if(!result)
{
returnDict = {"errCode":-1};
}
else
{
returnDict = {"errCode":1, "count":result};
}
});
response.send(returnDict);
});
});
// app.post('/users/add', function(request, response){
// });
// app.post('/TESTAPI/resetFixture', function(request, response){
// });
// app.post('/TESTAPI/unitTests', function(request, response){
// });
var port = process.env.PORT || 5000;
app.listen(port, function() {
console.log("Listening on " + port);
});
/*
pg.connect(process.env.DATABASE_URL, function(err, client) {
var query = client.query('SELECT * FROM your_table');
query.on('row', function(row) {
console.log(JSON.stringify(row));
});*/