|
|
|
@ -1,7 +1,7 @@ |
|
|
|
|
const express = require('express'); |
|
|
|
|
const app = express(); |
|
|
|
|
|
|
|
|
|
const fakeData = { |
|
|
|
|
const toolData = { |
|
|
|
|
categories: [ |
|
|
|
|
{ |
|
|
|
|
name: 'Woodshop', |
|
|
|
@ -48,17 +48,23 @@ const fakeData = { |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
user: { |
|
|
|
|
authorizedTools: [1, 2], |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const tools = { |
|
|
|
|
'2C3AE843A15F': { |
|
|
|
|
relayOn: false, |
|
|
|
|
ledOn: true, |
|
|
|
|
date: '2018-02-01', |
|
|
|
|
}, |
|
|
|
|
const user = { |
|
|
|
|
username: "protospace", |
|
|
|
|
name: "Protospace User", |
|
|
|
|
authorizedTools: [1, 2], |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const lockoutData = { |
|
|
|
|
lockouts: [ |
|
|
|
|
{ |
|
|
|
|
mac: '2C3AE843A15F', |
|
|
|
|
relayOn: false, |
|
|
|
|
ledOn: true, |
|
|
|
|
date: '2018-02-01', |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const server = app.listen(8080, function () { |
|
|
|
@ -73,17 +79,24 @@ app.use(function(req, res, next) { |
|
|
|
|
|
|
|
|
|
app.use('/', express.static('dist')); |
|
|
|
|
|
|
|
|
|
app.get('/api/client', function (req, res) { |
|
|
|
|
console.log('Request for client data'); |
|
|
|
|
app.get('/api/tooldata', function (req, res) { |
|
|
|
|
console.log('Request for tool data'); |
|
|
|
|
|
|
|
|
|
res.setHeader('Content-Type', 'application/json'); |
|
|
|
|
res.send(toolData); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
app.get('/api/user', function (req, res) { |
|
|
|
|
console.log('Request for user data'); |
|
|
|
|
|
|
|
|
|
res.setHeader('Content-Type', 'application/json'); |
|
|
|
|
res.send(fakeData); |
|
|
|
|
res.send(user); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
app.get('/api/tool/:mac', function (req, res) { |
|
|
|
|
app.get('/api/lockout/:mac', function (req, res) { |
|
|
|
|
const mac = req.params.mac; |
|
|
|
|
|
|
|
|
|
const data = tools[mac]; |
|
|
|
|
const data = lockoutData.lockouts.find(x => x.mac === mac); |
|
|
|
|
if (!data) { |
|
|
|
|
res.send(404); |
|
|
|
|
} |
|
|
|
|