express-exorcism
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -94,3 +94,2 @@ { | ||
], | ||
"no-throw-literal": 2, | ||
"no-eval": 2, | ||
@@ -97,0 +96,0 @@ "no-unneeded-ternary": 2, |
@@ -24,7 +24,5 @@ 'use strict'; | ||
var config = Object.assign({}, defaultConfig, userConfig); | ||
console.log('Using config: ', config); | ||
// Wraps Router's method with async resolver | ||
function methodWrapper(routerMethod, responseMethod) { | ||
console.log('[methodWrapper] wrapping ' + routerMethod + ' using response ' + responseMethod); | ||
return function () { | ||
@@ -36,22 +34,15 @@ var args = Array.prototype.slice.call(arguments); | ||
if (!handler || !handler.constructor || handler.constructor.name !== 'AsyncFunction') { | ||
console.log('[methodWrapper] Sync ' + routerMethod); | ||
return Router[PREFIX + routerMethod].apply(this, arguments); | ||
} | ||
console.log('[methodWrapper] Async ' + routerMethod + ' using response ' + responseMethod); | ||
return Router[PREFIX + routerMethod].apply(this, otherArguments.concat(function (req, res, next) { | ||
handler.apply(null, arguments) | ||
.then(function (result) { | ||
console.log('[Promise] success using ' + responseMethod); | ||
if (config.ignoreEmptyResolvedData && (result === null || result === undefined || result === false)) { | ||
console.log('[Promise] success, ignoring empty result'); | ||
return; | ||
} else if (responseMethod === 'none' || !res[responseMethod]) { | ||
console.log('[Promise] success, responseMethod === "none" or not exists'); | ||
return; | ||
} else if (responseMethod === 'end') { | ||
console.log('[Promise] success end'); | ||
res.end(); | ||
} else { | ||
console.log('[Promise] success - sending ' + responseMethod); | ||
res[responseMethod](result); | ||
@@ -61,3 +52,2 @@ } | ||
.catch(function (error) { | ||
console.log('[Promise catch] -> next'); | ||
next(error); | ||
@@ -77,3 +67,2 @@ }); | ||
.map(function (methodName) { | ||
console.log('Wrapping ' + methodName + ' using response ' + config.defaultResponseMethod); | ||
return { | ||
@@ -87,3 +76,2 @@ name: methodName, | ||
if (config.replaceOriginalMethods) { | ||
console.log('Replacing ' + method.name + ' with: ', method.wrapped); | ||
Router[method.name] = method.wrapped; | ||
@@ -90,0 +78,0 @@ } |
{ | ||
"name": "express-exorcism", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "", | ||
"main": "lib/express-exorcism.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha" | ||
}, | ||
"author": "Andrew G Kuznetsov <cav@cav.ru>", | ||
"license": "ISC", | ||
"engines": { | ||
"node": ">=7.5.0" | ||
}, | ||
"dependencies": { | ||
@@ -16,5 +19,7 @@ "is-promise": "^2.1.0", | ||
"devDependencies": { | ||
"express": "^4.16.2", | ||
"eslint": "^4.14.0" | ||
"chai": "^4.1.2", | ||
"chai-http": "^3.0.0", | ||
"eslint": "^4.14.0", | ||
"express": "^4.16.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
11484
13
346
2
1
57
4