overleaf/services/web/app/coffee/Features/Cooldown/CooldownMiddleware.coffee
Simon Detheridge 3553fb2d9d Merge pull request #1581 from sharelatex/spd-wearing-middle
Fix spelling of "middleware"

GitOrigin-RevId: d2b2b20ad8a6871cd6366303e75b340f0f2f2dda
2019-03-11 11:05:12 +00:00

17 lines
556 B
CoffeeScript

CooldownManager = require('./CooldownManager')
logger = require('logger-sharelatex')
module.exports = CooldownMiddleware =
freezeProject: (req, res, next) ->
projectId = req.params.Project_id
if !projectId?
return next(new Error('[Cooldown] No projectId parameter on route'))
CooldownManager.isProjectOnCooldown projectId, (err, projectIsOnCooldown) ->
if err?
return next(err)
if projectIsOnCooldown
logger.log {projectId}, "[Cooldown] project is on cooldown, denying request"
return res.sendStatus(429)
next()