refactor(app.js): Extract tooBusy
This commit is contained in:
parent
768943002c
commit
7ef17fd4e6
2 changed files with 15 additions and 8 deletions
10
app.js
10
app.js
|
@ -1,7 +1,7 @@
|
||||||
// app
|
// app
|
||||||
// external modules
|
// external modules
|
||||||
var express = require('express')
|
var express = require('express')
|
||||||
var toobusy = require('toobusy-js')
|
|
||||||
var ejs = require('ejs')
|
var ejs = require('ejs')
|
||||||
var passport = require('passport')
|
var passport = require('passport')
|
||||||
var methodOverride = require('method-override')
|
var methodOverride = require('method-override')
|
||||||
|
@ -146,13 +146,7 @@ server.on('resumeSession', function (id, cb) {
|
||||||
})
|
})
|
||||||
|
|
||||||
// middleware which blocks requests when we're too busy
|
// middleware which blocks requests when we're too busy
|
||||||
app.use(function (req, res, next) {
|
app.use(require('./lib/web/middleware/tooBusy'))
|
||||||
if (toobusy()) {
|
|
||||||
response.errorServiceUnavailable(res)
|
|
||||||
} else {
|
|
||||||
next()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
app.use(flash())
|
app.use(flash())
|
||||||
|
|
||||||
|
|
13
lib/web/middleware/tooBusy.js
Normal file
13
lib/web/middleware/tooBusy.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const toobusy = require('toobusy-js')
|
||||||
|
|
||||||
|
const response = require('../../response')
|
||||||
|
|
||||||
|
module.exports = function (req, res, next) {
|
||||||
|
if (toobusy()) {
|
||||||
|
response.errorServiceUnavailable(res)
|
||||||
|
} else {
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue