|
|
|
|
@ -1,6 +1,10 @@
|
|
|
|
|
const express = require('express');
|
|
|
|
|
const app = express();
|
|
|
|
|
|
|
|
|
|
app.use(express.json());
|
|
|
|
|
|
|
|
|
|
const measurements = [];
|
|
|
|
|
|
|
|
|
|
const sensors = [
|
|
|
|
|
{
|
|
|
|
|
id: 'htu21d-01',
|
|
|
|
|
@ -46,6 +50,30 @@ app.get('/api/sensors/:id', (req, res) => {
|
|
|
|
|
res.json(sensor);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.post('/api/measurements', (req, res) => {
|
|
|
|
|
//require json
|
|
|
|
|
//receive measurements
|
|
|
|
|
const measurement = req.body;
|
|
|
|
|
//verify type
|
|
|
|
|
// Content-type application/json
|
|
|
|
|
|
|
|
|
|
//validate submitted fields
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//store in memory
|
|
|
|
|
measurements.push(measurement);
|
|
|
|
|
|
|
|
|
|
//show in terminal
|
|
|
|
|
console.log('Received:', measurement);
|
|
|
|
|
|
|
|
|
|
//confirm status and storing
|
|
|
|
|
res.status(201).json(measurement);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.get('/api/measurements', (req, res) => {
|
|
|
|
|
res.json(measurements);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.listen(3030, () => {
|
|
|
|
|
console.log('Listen on port 3030');
|
|
|
|
|
});
|
|
|
|
|
|