let express = require('express'); let router = express.Router(); let keymap = {} router.get('/:id', (req, res) => { let key = req.params.id.toLowerCase(); if (key in keymap) { if (keymap[key] < Date.now()) { delete keymap[key]; res.status(403).json({status: 'Key Expired'}); } else { res.json({status: 'OK'}); } } else { res.status(404).json({status: 'Not found'}); } }); router.post('/', (req, res) => { if (!('key' in req.body && 'expires' in req.body)) { res.status(400).json({status: 'Bad Request'}); } let key = req.body.key.toLowerCase(); let expires = req.body.expires; if (key in keymap) { res.status(400).json({status: 'Key exists'}); } else { keymap[key] = expires res.json({status: 'OK'}); } }); router.delete('/:id', (req, res) => { let key = req.params.id.toLowerCase(); if (key in keymap) { delete keymap[key]; res.json({status: 'OK'}); } else { res.status(404).json({status: 'Not found'}); } }); module.exports = router;