31 lines
913 B
JavaScript
31 lines
913 B
JavaScript
const express = require('express');
|
|
const fs = require('fs');
|
|
|
|
var router = express.Router();
|
|
|
|
const path = __dirname + '/../database/data.json'
|
|
|
|
/* GET home page. */
|
|
router.get('/', function(req, res, next) {
|
|
res.json({ result: { success: true, data: 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[Number(req.params.index)] = data[Number(req.params.index)] ? false : true;
|
|
fs.writeFileSync(path, JSON.stringify(data));
|
|
}
|
|
res.send(null);
|
|
});
|
|
|
|
module.exports = router;
|