HHFSBRS/server/routes/index.js

31 lines
888 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(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);
});
module.exports = router;