-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
47 lines (40 loc) · 1.44 KB
/
server.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
var express = require('express');
var bodyParser = require('body-parser');
// database dependencies
var pg = require('pg');
var connectionString = 'postgres://localhost:5432/test';
// database users
var userTableSure = require('./server/models/users/userModel.js').userTableSure;
var userController = require('./server/models/users/userController.js');
// database trips
var tripTableSure = require('./server/models/trips/tripModel.js').tripTableSure;
var app = express();
var port = process.env.PORT || 8000;
app.use( bodyParser.json() ); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
app.use(express.static(__dirname + '/client'));
//app.use('/scripts', express.static(__dirname + '/bower_components'));
app.get('/', function(req, res){
res.send("Rideshare server up and running!");
});
app.get('/data', function (req, res) {
console.log("Get Received!");
var client = new pg.Client(connectionString);
userController.getUsers(req, res, client);
});
app.post('/data', function (req, res) {
console.log("Post received!");
console.log(req.body);
if (req.body) {
console.log(req.body);
var client = new pg.Client(connectionString);
userController.newUser(req.body.firstname, req.body.lastname, req, res, client);
}
});
app.listen(port, function() {
console.log('App up and running on http://localhost: ', port);
userTableSure();
tripTableSure();
});