50 lines
2.1 KiB
JavaScript
50 lines
2.1 KiB
JavaScript
var express = require('express');
|
|
var router = express.Router();
|
|
|
|
let timer = require('../controllers/timer');
|
|
|
|
// Express router entpoint to start the timer
|
|
router.get('/timerStart', function(req, res, next) {
|
|
if(timer.start()) { // If successfully started the timer
|
|
res.status(200); // Set http status code to 200 (success)
|
|
res.json(timer.getValues()); // Respond with all important values to update the frontend
|
|
} else { // If not successfull, for example because timer is already running or not time is left
|
|
res.status(406); // Set http status code to 406 (not acceptable)
|
|
res.send(); // Respond with empty payload
|
|
}
|
|
});
|
|
|
|
// Express router endpoint to pause the timer
|
|
router.get('/timerPause', function(req, res, next) {
|
|
if(timer.pause()) { // If successfully paused the timer
|
|
res.status(200); // Set http status code to 200 (success)
|
|
res.json(timer.getValues()); // Respond with all important values to update the frontend
|
|
} else { // If not successfull, for example if timer already is paused
|
|
res.status(406); // Set http status code to 406 (not acceptable)
|
|
res.send(); // Respond with empty payload
|
|
}
|
|
});
|
|
|
|
// Express router endpoint to reset the timer
|
|
router.post('/timerReset', function(req, res, next) {
|
|
timer.reset(req.body.duration); // Reset the timer with the duration in seconds received from the request
|
|
res.json(timer.getValues()); // Respond with all important values to update the frontend
|
|
});
|
|
|
|
// Express router endpoint to switch the score after halftime
|
|
router.get('/timerGetValues', function(req, res, next) {
|
|
res.json(timer.getValues()); // Respond with important values for frontend
|
|
});
|
|
|
|
res.render('admin');
|
|
});
|
|
|
|
/* GET home page. */
|
|
router.get('/', function(req, res, next) {
|
|
res.render('admin');
|
|
});
|
|
|
|
|
|
|
|
module.exports = router;
|