router.delete('/users/:userId', (req, res) => { const userIndex = getUserIndex(req.params.userId) if (userIndex === -1) return res.status(404).json({}) users.splice(userIndex, 1) res.json(users) })
router.use((req, res, next) => { if (!req.user) { res.status(401).json({ error: 'Unauthorized' }); return; } next(); });
app.use('/preview.html', function(req, res, next) { if (req.headers[config.INTERNAL_ID_HEADER] !== config.INTERNAL_ID) { return res.status(404).end('Not Found'); } next(); var index = req.path.indexOf('=') + 1; if (index) { var charset = req.path.substring(index); res.set('content-type', 'text/html;charset=' + charset); } });
router.post('/users', (req, res) => { const user = { id: ++userIdCounter, name: req.body.name } users.push(user) res.status(201).json(user) })
router.use('/users', (req, res, next) => { if (req.user && req.user.isAdmin) { next(); return; } res.status(401).send('Not authorized'); });
router.put('/users/:userId', (req, res) => { const user = getUser(req.params.userId) if (!user) return res.status(404).json({}) user.name = req.body.name res.json(user) })
router.use((req, res, next) => { if (!req.user || !req.user.isAdmin) { res.status(401).json({ error: 'Unauthorized' }); return; } next(); });
router.post('/users', (req, res) => { const user = { id: ++userIdCounter, name: req.body.name } users.push(user) res.status(201).json(user) })
router.put('/users/:userId', (req, res) => { const user = getUser(req.params.userId) if (!user) return res.status(404).json({}) user.name = req.body.name res.json(user) })
router.use((req, res, next) => { if (!req.user || !req.user.isAdmin) { res.status(401).json({ error: 'Unauthorized' }); return; } next(); });
router.use((req, res, next) => { if (!req.user || !req.user.isAdmin) { res.status(401).json({ error: 'Unauthorized' }); return; } next(); });
router.use((req, res, next) => { if (!req.user) { res.status(401).json({ error: 'Unauthorized' }); return; } next(); });
router.delete('/users/:userId', (req, res) => { const userIndex = getUserIndex(req.params.userId) if (userIndex === -1) return res.status(404).json({}) users.splice(userIndex, 1) res.json(users) })
router.use((req, res, next) => { if (!req.user || !req.user.isAdmin) { res.status(401).json({ error: 'Unauthorized' }); return; } next(); });