-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
61 lines (52 loc) · 1.46 KB
/
app.js
File metadata and controls
61 lines (52 loc) · 1.46 KB
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
52
53
54
55
56
57
58
59
60
61
const bodyParser = require("body-parser");
const cors = require("cors");
const express = require("express");
const config = require("./config");
const APIFunctions = require("./APIFunctions")
const mongoHelpers = require('./mongoFunctions.js');
const app = express();
const port = 3000;
console.log("Running in node environment: " + process.env.NODE_ENV);
app.set('json spaces', 2)
app.use(cors({ origin: true, credentials: true }));
app.options("*", cors());
app.use(express.json());
app.get('/healthcheck', (req, res) => {
res.status(200).json([{
status: 'Still Alive'
}])
})
app.post('/uploaduser', APIFunctions.isAuthorized, (req, res) => {
var response;
try {
response = APIFunctions.uploadNewUser(req.body);
}
catch (err) {
res.status(400).json([{
status: 'Failure from Mongo'
}])
}
res.status(200).json([{
status: 'Uploaded User',
user: req.body,
result: response
}])
})
app.post("/getdata", APIFunctions.isAuthorized, async (req, res) => {
let temp = await APIFunctions.getAQIData(req.body);
res.send(temp);
});
app.get("/notifyUsers", APIFunctions.isAuthorized, async (req, res) => {
APIFunctions.notifyUsers(req);
res.json([
{
status: "Texting users",
},
]);
});
//TEST FUNCTIONS
app.post("/text", APIFunctions.isAuthorized, async (req, res) => {
APIFunctions.textUser(req.body.content, req.body.phone);
res.send("texting?");
});
app.listen(port, () => console.log(`Listening on port ${port}`));