-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (45 loc) · 1.28 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
const five = require("johnny-five"),
// board = new five.Board(),
express = require('express'),
app = express(),
profiles = require('./settings/profile'),
path = require('path'),
bodyParser = require('body-parser');
const jsonParser = bodyParser.json();
app.use('/static', express.static(path.join(__dirname, 'static')))
let startServer = () => {
// let siren = new five.Led(13);
app.listen(3000, () => {
console.log('Running Server at port 3000');
});
app.get('/', (req, res) => {
res.sendFile(`${__dirname}/pages/main.html`);
});
app.get('/profiles', (req, res) => {
res.send(profiles.get());
});
app.post('/profiles', jsonParser, (req, res) => {
let body = req.body;
if (body) {
profiles.update(body.index, body.data);
}
res.send(profiles.get());
});
app.delete('/profiles/:index', jsonParser, (req, res) => {
let index = parseInt(req.params.index, 10);
if (index > -1) {
profiles.remove(index);
}
res.send(profiles.get());
});
app.get('/on', (req, res) => {
// siren.on();
res.send('Ligado!');
});
app.get('/off', (req, res) => {
// siren.off();
res.send('Desligado!');
});
}
startServer();
// board.on("ready", startServer );