Start firmware
This commit is contained in:
@@ -87,14 +87,14 @@ let toolStatus = lockoutData.lockouts.map(x => (
|
||||
{
|
||||
id: x.id,
|
||||
on: false,
|
||||
armable: false,
|
||||
armed: false,
|
||||
user: null,
|
||||
}
|
||||
));
|
||||
|
||||
console.log(toolStatus);
|
||||
|
||||
const server = app.listen(8080, function () {
|
||||
const server = app.listen(8080, () => {
|
||||
console.log('Example app listening on port 8080!');
|
||||
});
|
||||
const io = require('socket.io')(server);
|
||||
@@ -102,7 +102,7 @@ const io = require('socket.io')(server);
|
||||
// Express http server stuff:
|
||||
|
||||
// TODO : remove on prod
|
||||
app.use(function(req, res, next) {
|
||||
app.use((req, res, next) => {
|
||||
res.header('Access-Control-Allow-Origin', '*');
|
||||
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
|
||||
next();
|
||||
@@ -110,32 +110,34 @@ app.use(function(req, res, next) {
|
||||
|
||||
app.use('/', express.static('dist'));
|
||||
|
||||
app.get('/api/tooldata', function (req, res) {
|
||||
app.get('/api/tooldata', (req, res) => {
|
||||
console.log('Request for tool data');
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(toolData);
|
||||
});
|
||||
|
||||
app.get('/api/user', function (req, res) {
|
||||
app.get('/api/user', (req, res) => {
|
||||
console.log('Request for user data');
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(users[0]);
|
||||
});
|
||||
|
||||
app.get('/api/lockout/:mac', function (req, res) {
|
||||
app.post('/api/lockout/:mac', (req, res) => {
|
||||
const mac = req.params.mac;
|
||||
|
||||
const data = lockoutData.lockouts.find(x => x.mac === mac);
|
||||
const lockout = lockoutData.lockouts.find(x => x.mac === mac);
|
||||
if (!data) {
|
||||
res.send(404);
|
||||
}
|
||||
|
||||
const tool = toolStatus.find(x => x.id === lockout.id);
|
||||
|
||||
console.log('Request from MAC: ' + mac);
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(JSON.stringify(data));
|
||||
res.send(JSON.stringify({ armable: tool.armable }));
|
||||
});
|
||||
|
||||
// Socket.io websocket stuff:
|
||||
@@ -159,11 +161,10 @@ io.on('connection', socket => {
|
||||
const toolIndex = toolStatus.findIndex(x => x.id === toolId);
|
||||
let tool = toolStatus[toolIndex];
|
||||
|
||||
if (action === 'arm' && !tool.armed && !tool.on) {
|
||||
tool.armed = true;
|
||||
} else if (action === 'disarm' && tool.armed) {
|
||||
tool.armed = false;
|
||||
tool.on = false;
|
||||
if (action === 'arm') {
|
||||
tool.armable = true;
|
||||
} else if (action === 'disarm') {
|
||||
tool.armable = false;
|
||||
}
|
||||
|
||||
toolStatus[toolIndex] = tool;
|
||||
|
Reference in New Issue
Block a user