-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
34 lines (27 loc) · 944 Bytes
/
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
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
var fanData = 0;
app.use(express.static(__dirname + '/views'));
app.use(bodyParser.json({ type: 'application/*+json' }))
app.use(bodyParser.text({ type: 'text/html' }));
app.use(bodyParser.json());
app.get('/Login', (req, res) => {
// should be a key that the server generates to establish a secure connection
res.send('1234');
});
app.get('/FanSpeed', (req,res) => {
res.header('Auth', '1234');
res.send('' + fanData);
});
app.get('/Ping', (req, res) => {
res.send('Is your name WiFi? Cause I\'m feeling a connection. ;)');
});
app.post('/Update', (req, res) => {
fanData = req.body.fanData;
console.log('req: ' + JSON.stringify(req.body));
res.send('Updated local data: ' + fanData);
});
// PORT
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Listening on port ${port}`));