From 46a57f5d5cde9e54ac9a1c14d626943570633109 Mon Sep 17 00:00:00 2001 From: akhoury Date: Fri, 24 Jun 2016 16:57:58 -0400 Subject: [PATCH] rm cls because it's not ready yet --- app.js | 1 - package.json | 1 - src/middleware/cls.js | 38 -------------------------------------- src/middleware/index.js | 4 +--- src/plugins/hooks.js | 29 ----------------------------- src/socket.io/index.js | 18 +++--------------- 6 files changed, 4 insertions(+), 87 deletions(-) delete mode 100644 src/middleware/cls.js diff --git a/app.js b/app.js index b40ec938a4..9c202470ad 100644 --- a/app.js +++ b/app.js @@ -22,7 +22,6 @@ var nconf = require('nconf'); nconf.argv().env('__'); -require('continuation-local-storage'); var url = require('url'), async = require('async'), diff --git a/package.json b/package.json index 1229d899d2..868f143a96 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,6 @@ "connect-mongo": "~1.1.0", "connect-multiparty": "^2.0.0", "connect-redis": "~3.0.2", - "continuation-local-storage": "^3.1.6", "cookie-parser": "^1.3.3", "cron": "^1.0.5", "csurf": "^1.6.1", diff --git a/src/middleware/cls.js b/src/middleware/cls.js deleted file mode 100644 index 8cf0062d30..0000000000 --- a/src/middleware/cls.js +++ /dev/null @@ -1,38 +0,0 @@ -var path = require('path'); -var sockets = require('path'); -var websockets = require('../socket.io/'); -var continuationLocalStorage = require('continuation-local-storage'); -var APP_NAMESPACE = require(path.join(__dirname, '../../package.json')).name; -var namespace = continuationLocalStorage.createNamespace(APP_NAMESPACE); - -(function(cls) { - cls.http = function (req, res, next) { - namespace.run(function() { - namespace.set('request', req); - next && next(); - }); - }; - - cls.socket = function (socket, payload, event, next) { - namespace.run(function() { - namespace.set('request', websockets.reqFromSocket(socket, payload, event)); - next && next(); - }); - }; - - cls.get = function (key) { - return namespace.get(key); - }; - - cls.set = function (key, value) { - return namespace.set(key, value); - }; - - cls.setItem = cls.set; - cls.getItem = cls.get; - cls.namespace = namespace; - cls.continuationLocalStorage = continuationLocalStorage; - -})(exports); - - diff --git a/src/middleware/index.js b/src/middleware/index.js index 2e39bb6d70..867af6fed2 100644 --- a/src/middleware/index.js +++ b/src/middleware/index.js @@ -14,7 +14,6 @@ var meta = require('../meta'), compression = require('compression'), favicon = require('serve-favicon'), session = require('express-session'), - cls = require('./cls'), useragent = require('express-useragent'); @@ -62,7 +61,7 @@ module.exports = function(app) { if (nconf.get('secure')) { cookie.secure = true; } - + if (relativePath !== '') { cookie.path = relativePath; } @@ -78,7 +77,6 @@ module.exports = function(app) { app.use(middleware.addHeaders); app.use(middleware.processRender); - app.use(cls.http); auth.initialize(app, middleware); return middleware; diff --git a/src/plugins/hooks.js b/src/plugins/hooks.js index 005255582f..c2dde7b92a 100644 --- a/src/plugins/hooks.js +++ b/src/plugins/hooks.js @@ -7,29 +7,6 @@ module.exports = function(Plugins) { Plugins.deprecatedHooks = { 'filter:user.custom_fields': null // remove in v1.1.0 }; - - Plugins.deprecatedHooksParams = { - 'action:homepage.get': '{req, res}', - 'filter:register.check': '{req, res}', - 'action:user.loggedOut': '{req, res}', - 'static:user.loggedOut': '{req, res}', - 'filter:categories.build': '{req, res}', - 'filter:category.build': '{req, res}', - 'filter:group.build': '{req, res}', - 'filter:register.build': '{req, res}', - 'filter:composer.build': '{req, res}', - 'filter:popular.build': '{req, res}', - 'filter:recent.build': '{req, res}', - 'filter:topic.build': '{req, res}', - 'filter:users.build': '{req, res}', - 'filter:admin.category.get': '{req, res}', - 'filter:middleware.renderHeader': '{req, res}', - 'filter:widget.render': '{req, res}', - 'filter:middleware.buildHeader': '{req, locals}', - 'action:middleware.pageView': '{req}', - 'action:meta.override404': '{req}' - }; - /* `data` is an object consisting of (* is required): `data.hook`*, the name of the NodeBB hook @@ -62,12 +39,6 @@ module.exports = function(Plugins) { parts.pop(); } var hook = parts.join(':'); - if (Plugins.deprecatedHooksParams[hook]) { - winston.warn('[plugins/' + id + '] Hook `' + hook + '` parameters: `' + Plugins.deprecatedHooksParams[hook] + '`, are being deprecated, ' - + 'all plugins should now use the `middleware/cls` module instead of hook\'s arguments to get a reference to the `http-request` or the `socket-request` object(s) (from which you can get the current `uid` if you need to.) ' - + '- for more info, visit https://docs.nodebb.org/en/latest/plugins/create.html#getting-a-reference-to-each-request-from-within-any-plugin-hook\n'); - delete Plugins.deprecatedHooksParams[hook]; - } } if (data.hook && data.method) { diff --git a/src/socket.io/index.js b/src/socket.io/index.js index 89459c50b3..772166687a 100644 --- a/src/socket.io/index.js +++ b/src/socket.io/index.js @@ -11,7 +11,6 @@ var url = require('url'); var db = require('../database'); var logger = require('../logger'); var ratelimit = require('../middleware/ratelimit'); -var cls = require('../middleware/cls'); (function(Sockets) { var Namespaces = {}; @@ -30,7 +29,6 @@ var cls = require('../middleware/cls'); io.use(authorize); io.on('connection', onConnection); - io.on('disconnect', onDisconnect); io.listen(server, { transports: nconf.get('socket.io:transports') @@ -44,14 +42,10 @@ var cls = require('../middleware/cls'); logger.io_one(socket, socket.uid); - cls.socket(socket, null, 'connection', function () { - onConnect(socket); - }); + onConnect(socket); socket.on('*', function (payload) { - cls.socket(socket, payload, null, function () { - onMessage(socket, payload); - }); + onMessage(socket, payload); }); } @@ -64,12 +58,6 @@ var cls = require('../middleware/cls'); } } - function onDisconnect(socket) { - cls.socket(socket, null, 'disconnect', function () { - }); - } - - function onMessage(socket, payload) { if (!payload.data.length) { return winston.warn('[socket.io] Empty payload'); @@ -235,4 +223,4 @@ var cls = require('../middleware/cls'); }; }; -})(exports); \ No newline at end of file +})(exports);