Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add toobusy module

  • Loading branch information...
commit 34af364383467a5d77f514c7a6486f1787eb1ec4 1 parent a0691f1
@nomospace authored
View
2  .travis.yml
@@ -1,3 +1,3 @@
language: node_js
node_js:
- - 0.6
+ - 0.8
View
5 app.js
@@ -5,7 +5,7 @@ var ejs = require('ejs');
var fs = require('fs');
var express = require('express');
var app = express();
-var authUser = require('./controllers/sign').authUser;
+var sign = require('./controllers/sign');
var config = require('./config').config;
var routes = require('./routes');
var appRoot = './';
@@ -29,7 +29,8 @@ app.configure('development', function() {
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({secret: config.sessionSecret}));
- app.use(authUser);
+ app.use(sign.authUser);
+ app.use(sign.toobusy);
app.use(partials());
app.use(express.static(path.join(appRoot, 'public')));
// 在 HTML 页面中显示程序传递和抛出的异常
View
2  config.js
@@ -3,7 +3,7 @@ exports.config = {
debug: true,
name: 'nodemail',
description: '基于 nodejs 的 web 邮箱',
- version: '0.1.6',
+ version: '0.1.7',
sessionSecret: 'nodemail',
authCookieName: 'nodemail',
View
9 controllers/sign.js
@@ -1,5 +1,6 @@
var sanitize = require('validator').sanitize;
var crypto = require('crypto');
+var toobusy = require('toobusy');
var config = require('../config').config;
var mailUtil = require('../libs/mail-util');
@@ -56,6 +57,14 @@ exports.authUser = function(req, res, next) {
return next();
};
+exports.toobusy = function(req, res, next) {
+ if (toobusy()) {
+ res.send(503, '系统忙,请稍后再试');
+ } else {
+ next();
+ }
+};
+
// private
function genSession(user, res) {
var authToken = encrypt(user.name + '\t' + user.pass, config.sessionSecret);
View
3  package.json
@@ -28,7 +28,8 @@
"moment": "~1.7.0",
"nodemailer": "~0.3.27",
"validator": "~0.4.11",
- "mongoose": "~3.1.2"
+ "mongoose": "~3.1.2",
+ "toobusy": "~0.1.1"
},
"devDependencies": {},
"scripts": {
Please sign in to comment.
Something went wrong with that request. Please try again.