|
|
|
@ -69,6 +69,21 @@ app.get('/api/measurements', (req, res) => {
|
|
|
|
res.json(measurements);
|
|
|
|
res.json(measurements);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.get('/api/measurements/latest', (req, res) => {
|
|
|
|
|
|
|
|
// Check whether any measurements exist.
|
|
|
|
|
|
|
|
if (measurements.length === 0) {
|
|
|
|
|
|
|
|
return res.status(404).json({
|
|
|
|
|
|
|
|
error: 'No measurements yet'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The last array element is the latest submitted measurement.
|
|
|
|
|
|
|
|
const latest = measurements[measurements.length - 1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res.json(latest);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// starting the listening service
|
|
|
|
// starting the listening service
|
|
|
|
app.listen(3030, () => {
|
|
|
|
app.listen(3030, () => {
|
|
|
|
console.log('Server running at http://localhost:3030');
|
|
|
|
console.log('Server running at http://localhost:3030');
|
|
|
|
|