forked from thebookins/shareup
-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
49 lines (40 loc) · 1.24 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
48
49
const express = require("express");
const bodyParser = require("body-parser");
// const storage = require('node-persist');
const client = require('redis').createClient(process.env.REDIS_URL);
const app = express();
app.use(bodyParser.json());
// Create link to Angular build directory
const distDir = __dirname + "/dist/";
app.use(express.static(distDir));
// storage.init().then(() => {
// Initialize the app.
const server = app.listen(process.env.PORT || 8080, function () {
var port = server.address().port;
console.log("App now running on port", port);
});
// });
client.get('status', (err, val) => {
if (!val) {
client.set('status', JSON.stringify({at: new Date(0).toISOString(), up: false, since: new Date(0).toISOString()}))
}
});
// STATUS API ROUTES BELOW
/* "/api/status"
* GET: finds all statuses
*/
app.get("/api/status", function(req, res) {
client.get("status", function(err, reply) {
// reply is null when the key is missing
// TODO: add if (reply) or something
res.status(200).json(JSON.parse(reply));
});
// storage.values().then(values => {
// res.status(200).json(values);
// });
});
/* "/api/status/:id"
* GET: find status by id
*/
app.get("/api/status/:id", function(req, res) {
});