HHFSBRS/server/routes/index.js

31 lines
913 B
JavaScript
Raw Permalink Normal View History

2019-10-29 15:08:56 +01:00
const express = require('express');
const fs = require('fs');
2019-10-29 14:47:53 +01:00
var router = express.Router();
2019-10-29 17:21:52 +01:00
const path = __dirname + '/../database/data.json'
2019-10-29 14:47:53 +01:00
/* GET home page. */
router.get('/', function(req, res, next) {
res.json({ result: { success: true, data: JSON.parse(fs.readFileSync(path).toString())}});
2019-10-29 17:21:52 +01:00
});
router.post('/login', (req, res, _next) => {
if (req.body.username === 'Mediatheek' && req.body.password === '@MediatheekHetHeerenlanden!') {
res.json(true)
} else {
res.json(false);
}
});
router.post('/update/:index', (req, res, _next) => {
if (req.body.username === 'Mediatheek' && req.body.password === '@MediatheekHetHeerenlanden!') {
const data = JSON.parse(fs.readFileSync(path).toString());
data[Number(req.params.index)] = data[Number(req.params.index)] ? false : true;
2019-10-29 17:21:52 +01:00
fs.writeFileSync(path, JSON.stringify(data));
}
res.send(null);
2019-10-29 14:47:53 +01:00
});
module.exports = router;