-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
43 lines (31 loc) · 1.06 KB
/
index.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
const express = require('express');
const exphbs = require('express-handlebars');
const pgp = require('pg-promise')();
const app = express();
const PORT = process.env.PORT || 3019;
let useSSL = false;
let local = process.env.LOCAL || false;
if (process.env.DATABASE_URL && !local) {
useSSL = true;
}
// TODO configure this to work.
const connectionString = process.env.DATABASE_URL || 'postgresql://@localhost:5432/mango_market';
const db = pgp(connectionString);
// enable the req.body object - to allow us to use HTML forms
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// enable the static folder...
app.use(express.static('public'));
// add more middleware to allow for templating support
app.engine('handlebars', exphbs.engine());
app.set('view engine', 'handlebars');
let counter = 0;
app.get('/', function(req, res) {
res.render('index', {
counter
});
});
// start the server and start listening for HTTP request on the PORT number specified...
app.listen(PORT, function() {
console.log(`MangoApp started on port ${PORT}`)
});