pslockout/webserver/server.js

31 lines
575 B
JavaScript
Raw Normal View History

2018-02-02 06:46:44 +00:00
const express = require('express');
const app = express();
const tools = {
"2C3AE843A15F": {
relayOn: false,
ledOn: true,
date: "2018-02-01",
},
};
const server = app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
app.use('/', express.static('dist'));
app.get('/api/tool/:mac', function (req, res) {
const mac = req.params.mac;
const data = tools[mac];
if (!data) {
res.send(404);
}
console.log("Request from MAC: " + mac);
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify(data));
});