diff options
author | BoHong Li | 2017-04-12 06:05:43 +0800 |
---|---|---|
committer | Raccoon Li | 2017-05-08 19:29:06 +0800 |
commit | 7ef17fd4e61503178875dd34f998203264ffb691 (patch) | |
tree | 0e8d40efdea92676bf579cc127fae1eb2c5e1a4e | |
parent | 768943002c7f9bdac7f674338f18e567c16bda52 (diff) |
refactor(app.js): Extract tooBusy
Diffstat (limited to '')
-rw-r--r-- | app.js | 10 | ||||
-rw-r--r-- | lib/web/middleware/tooBusy.js | 13 |
2 files changed, 15 insertions, 8 deletions
@@ -1,7 +1,7 @@ // app // external modules var express = require('express') -var toobusy = require('toobusy-js') + var ejs = require('ejs') var passport = require('passport') var methodOverride = require('method-override') @@ -146,13 +146,7 @@ server.on('resumeSession', function (id, cb) { }) // middleware which blocks requests when we're too busy -app.use(function (req, res, next) { - if (toobusy()) { - response.errorServiceUnavailable(res) - } else { - next() - } -}) +app.use(require('./lib/web/middleware/tooBusy')) app.use(flash()) diff --git a/lib/web/middleware/tooBusy.js b/lib/web/middleware/tooBusy.js new file mode 100644 index 00000000..f1b72330 --- /dev/null +++ b/lib/web/middleware/tooBusy.js @@ -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() + } +} |