forked from cityofaustin/ctxfloods-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocalServer.js
110 lines (92 loc) · 3.4 KB
/
localServer.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const express = require('express');
const cors = require('cors');
const xmlHandler = require('./handlers/xmlHandler');
const wazeFeedHandler = require('./handlers/wazeFeedHandler');
const incidentReportHandler = require('./handlers/incidentReportHandler');
const graphqlHandler = require('./handlers/graphqlHandler');
const resetEmailHandler = require('./handlers/resetEmailHandler');
const syncLegacyHandler = require('./handlers/syncLegacyHandler');
const pushNotificationHandler = require('./handlers/pushNotificationHandler');
const cameraScrapeHandler = require('./handlers/cameraScrapeHandler');
const app = express();
app.use(cors());
app.use(express.json({ limit: '500kb', extended: true})); // High Limit is required for scrape_cameras
app.use(express.urlencoded({ limit: '500kb', extended: true }));
app.get('/xml', (req, res) => {
xmlHandler.handle(null, null, (error, response) => {
res.statusCode = response.statusCode;
res.setHeader('Content-Type', response.headers['Content-Type']);
res.send(response.body);
});
});
app.get('/waze/feed', (req, res) => {
wazeFeedHandler.handle(null, null, (error, response) => {
res.statusCode = response.statusCode;
res.setHeader('Content-Type', response.headers['Content-Type']);
res.send(response.body);
});
});
// POST /graphql
app.use(graphqlHandler.handle);
app.post('/incident/report', (req, res) => {
// AWS gets body as stringified json
req.body = JSON.stringify(req.body);
incidentReportHandler.handle(req, null, (error, response) => {
res.statusCode = response.statusCode;
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Content-Type', response.headers['Content-Type']);
res.send(response.body);
});
});
app.post('/email/reset', (req, res) => {
// AWS gets body as stringified json
req.body = JSON.stringify(req.body);
resetEmailHandler.handle(req, null, (error, response) => {
res.statusCode = response.statusCode;
res.setHeader('Access-Control-Allow-Origin', '*');
res.send(response);
});
});
app.get('/sync_legacy', (req, res) => {
// AWS gets body as stringified json
req.body = JSON.stringify(req.body);
syncLegacyHandler.handle(req, null, (error, response) => {
res.statusCode = response.statusCode;
res.setHeader('Access-Control-Allow-Origin', '*');
res.send(response);
});
});
app.get('/send_push_notifications', (req, res) => {
// AWS gets body as stringified json
req.body = JSON.stringify(req.body);
pushNotificationHandler.handle(req, null, (error, response) => {
res.statusCode = response.statusCode;
res.setHeader('Access-Control-Allow-Origin', '*');
res.send(response);
});
});
app.get('/scrape_cameras', (req, res) => {
// AWS gets body as stringified json
req.body = JSON.stringify(req.body);
cameraScrapeHandler.handle(req, null, (error, response) => {
res.statusCode = response.statusCode;
res.setHeader('Access-Control-Allow-Origin', '*');
res.send(response);
});
});
const server = app.listen(process.env.BACKEND_PORT, () => {
console.log('Local Server started');
});
process.on('SIGTERM', () => {
console.log('Signal Terminated - closing express server');
server.close();
});
process.on('SIGINT', () => {
console.log('Signal Interrupted - closing express server');
server.close();
});
process.on('exit', () => {
console.log("Process Exiting - closing express server");
server.close();
})
module.exports = server;