-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (56 loc) · 1.45 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
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
const express = require('express')
const fetch = require('node-fetch')
const ddos = require('ddos')
const bodyparser = require('body-parser')
const helmet = require('helmet')
const { URLSearchParams } = require('url');
const app = express();
const params = new URLSearchParams();
const Ddos = new ddos({
burst: 30,
limit: 30,
maxCount: 80,
checkInterval: 5,
errormessage: "You have been blocked by attemped too many requests"
})
params.append('site', 24);
params.append('siteType', 4);
const settings = {
method: 'POST',
body: params
}
app.use(Ddos.express)
app.use(bodyparser.urlencoded({
extended: true
}));
app.use(bodyparser.json());
app.use(helmet());
app.get('/', async(req, res) => {
fetch('http://www.emtrontech.com/iaqnode/getSpecSiteData.php', settings)
.then(response => response.json())
.then(data => res.status(200).json({
success: true,
lastUpdate: data.d.lastUpdate,
temp: data.d.tempDevice,
humidity: data.d.RhumidDevice,
pm25: data.d.Rpm25Device,
pm25Avg: data.d.pm25Device,
pm10: data.d.Rpm10Device,
pm10Avg: data.d.pm10Device,
co2: data.d.Rco2Device
}))
})
const run = async (app) => {
try {
await app.listen(3000, () => {
console.log(`Running on port 3000`);
})
} catch(error) {
console.warn(error)
process.exit(0)
}
}
module.exports = {
app,
run
}