Skip to content
Permalink
Browse files

chore(router): support app.beforeStart in http router

  • Loading branch information...
huangyoukun committed Jun 25, 2018
1 parent 86257db commit f51c7c2e14bc4042f76c294a822579e919b9949f
Showing with 14 additions and 5 deletions.
  1. +14 −5 bin/proxy/http.route.js
@@ -540,9 +540,18 @@ function doRoute(req, res) {
if (modulePath && typeof modulePath.callback === 'function') {
const app = modulePath;

modulePath = function(req, res, plug) {
return app.callback()(req, res);
};
// if beforeStart exists
if (typeof app.beforeStart === 'function') {
modulePath = function(req, res, plug) {
return app.beforeStart(function() {
app.callback()(req, res);
});
};
} else {
modulePath = function(req, res, plug) {
return app.callback()(req, res);
};
}
}

if (typeof modulePath !== 'function') {
@@ -584,8 +593,8 @@ function doRoute(req, res) {

const blackIpMap = TSW.getBlockIpMapSync() || {};

if (blackIpMap[clientIp] || blackIpMap[userIp24] || !clientIp) {
logger.debug('连接已断开');
if (!clientIp) {
logger.debug('client ip is empty');

tnm2.Attr_API('SUM_TSW_IP_EMPTY', 1);
res.writeHead(403, { 'Content-Type': 'text/plain; charset=UTF-8' });

0 comments on commit f51c7c2

Please sign in to comment.
You can’t perform that action at this time.