-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathco.app.js
51 lines (43 loc) · 1.32 KB
/
co.app.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
const express = require('express'),
path = require('path'),
logger = require('morgan'),
bodyParser = require('body-parser'),
app = express(),
http = require('http'),
{ Client } = require('pg');
console.log('*** co.app.js accessed');
app.use('/', (req, res, next) => next(), express.static('public/co-app'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(async (req, res, next) => {
// TODO: store secrets somewhere secure
const client = new Client({
user: 'postgres',
password: 'p4ssw0rd',
host: 'aws.datagotchi.net',
port: 5432,
database: 'counteroffer'
});
console.log('*** connecting to postgres client...');
await client.connect(); // FIXME: not connecting to the db
console.log('*** postgres client connected');
req.client = client;
next();
});
const index = require('./routes/co-app');
app.use('/', index);
console.log('*** routes added');
const server = http.createServer(app);
server.listen(process.env.PORT || 3002);
server.on('listening', () => {
console.log('Listening on ', server.address());
});
app.use(function(err, req, res, next) {
console.log('error! ' + err);
return res.status(err.status || 500).json({
message: err.message,
error: err
});
});
module.exports = app;