-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (29 loc) · 1.16 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
const Trello = require("./src/trello.js"),
express = require('express'),
cors = require('cors'),
path = require('path'),
app = express();
let trelloData = null,
trelloDataTimeStamp = null;
app.set('port', (process.env.PORT || 5000));
app.use(express.static(path.join(__dirname, 'client/build')));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
app.use(cors());
app.get('/assignments', async (request, response) => {
if (!trelloDataTimeStamp || (Date.now() > trelloDataTimeStamp + 300000)) {
trelloData = await Trello.getTrelloData();
trelloDataTimeStamp = Date.now();
}
response.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8', 'Content-Encoding': 'utf-8' })
response.end(JSON.stringify(trelloData));
});
app.get('/resetcache', async (request, response) => {
trelloDataTimeStamp = null;
response.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8', 'Content-Encoding': 'utf-8' })
response.end('cache reset');
});
app.listen(app.get('port'), function () {
console.log(`Node app is running at localhost: ${app.get('port')}`);
});