-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
43 lines (34 loc) · 1.03 KB
/
app.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
const express = require('express')
const bodyParses = require('body-parser')
var request = require('request');
const app = express()
const path = require('path');
const port = process.env.PORT || 8080;
app.use(express.static(__dirname + '/public'));
app.use(bodyParses.json());
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '../html/index.html'));
})
app.post('/oximeterValues', function (request, response) {
let body={"data":request.body,"type":"SetData"};
sendCommand(body);
response.send(body); // echo the result back
});
app.post('/oximeterState', function (request, response) {
let body={"data":request.body,"type":"Power"};
sendCommand(body);
});
const sendCommand=(body)=>{
request({
url: 'http://localhost:5000/command',
method: "POST",
json: true,
body: body
}, function (error, response, body) {
console.log(response);
});
response.send(req.body); // echo the result back
}