-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
30 lines (27 loc) · 904 Bytes
/
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
const express = require('express')
const path = require('path')
const { Client } = require('pg');
const pepper = require('./pepper.js');
const spin = require('./spin.js');
const PORT = process.env.PORT || 5000
const ssl = process.env.DATABASE_URL.startsWith('postgres://localhost')
? false
: { rejectUnauthorized: false }
const db = new Client({
connectionString: process.env.DATABASE_URL,
ssl
});
db.connect();
console.log("Database connected");
express()
.set('views', path.join(__dirname, 'views'))
.set('view engine', 'ejs')
.get('/leaders', async (req, res) => {
const results = await pepper.leadersResults(db);
res.render('pages/leaders', {'results': results})
})
.get('/queue', async (req, res) => {
const results = await spin.getQueue(db);
res.render('pages/queue', {'results': results})
})
.listen(PORT, () => console.log(`Listening on ${ PORT }`))