-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
33 lines (26 loc) · 850 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 app = express();
const server = require('http').createServer(app);
var io = require('socket.io')(server);
var PumpController = require('./PumpController.js');
app.get('/', (req, res, next) => {
res.sendFile(__dirname + '/index.html')
});
var array = [];
app.get('/pump', (req, res, next) => {
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({ a: 1 }));
});
const port = process.env.PORT || 1337;
server.listen(port);
console.log(`Local server listening on http://localhost:${port}`);
console.log(`Live server listening on 93.167.121.188:${port}`);
PumpController.init((relay) =>{
io.on('connection', function (socket) {
socket.emit('initialized', false);
socket.on('toggle', function (data) {
console.log(data);
relay.toggle();
});
});
});