multy-stub/server/routers/epja-2023-2/example/index.js
2023-11-20 18:58:08 +03:00

27 lines
566 B
JavaScript

const express = require("express");
const router = express.Router()
const waitMiddleware = (req, res, next) => {
setTimeout(() => {
next()
}, 3000)
}
const listActivated = true
router.get('/list', waitMiddleware, (req, res) => {
req.user
if (listActivated) {
res.status(200).send(require('./news.json'))
} else {
res.status(500).send()
}
})
router.get('/list-activate-toggle', (req, res) => {
listActivated = !listActivated
res.send(listActivated ? 'Activated' : 'Deactivated')
})
module.exports = router