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) {
|
2019-10-29 17:21:52 +01:00
|
|
|
res.json(JSON.parse(fs.readFileSync(path).toString()));
|
|
|
|
});
|
|
|
|
|
|
|
|
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.data[Number(req.params.index)] = data.data[Number(req.params.index)] ? false : true;
|
|
|
|
fs.writeFileSync(path, JSON.stringify(data));
|
|
|
|
}
|
|
|
|
res.send(null);
|
2019-10-29 14:47:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = router;
|