Socket
Socket
Sign inDemoInstall

egg-core

Package Overview
Dependencies
Maintainers
4
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-core - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

6

History.md
1.2.0 / 2016-11-21
==================
* refactor: don't use core middleware when enable = false (#32)
* feat: core middlewares support enable/match/ignore options (#31)
1.1.0 / 2016-11-09

@@ -3,0 +9,0 @@ ==================

32

lib/loader/mixin/middleware.js

@@ -7,2 +7,3 @@ 'use strict';

const inspect = require('util').inspect;
const pathMatching = require('egg-path-matching');

@@ -48,2 +49,3 @@ module.exports = {

debug('middlewareNames: %j', middlewareNames);
const middlewaresMap = new Map();
for (const name of middlewareNames) {

@@ -53,2 +55,6 @@ if (!app.middlewares[name]) {

}
if (middlewaresMap.has(name)) {
throw new TypeError(`Middleware ${name} redefined`);
}
middlewaresMap.set(name, true);

@@ -62,5 +68,15 @@ const options = this.config[name] || {};

mw._name = name;
app.use(mw);
debug('Use middleware: %s with options: %j', name, options);
this.options.logger.info('[egg:loader] Use middleware: %s', name);
// core middleware support options.enable, options.ignore and options.match
const isCoreMiddleware = this.config.coreMiddleware.indexOf(name) >= 0;
if (isCoreMiddleware) {
if (options.enable !== false) {
app.use(wrapCoreMiddleware(mw, options));
debug('Use core middleware: %s with options: %j', name, options);
}
} else {
app.use(mw);
debug('Use app middleware: %s with options: %j', name, options);
}
this.options.logger.info('[egg:loader] Use %s middleware: %s', isCoreMiddleware ? 'core' : 'app', name);
}

@@ -72,1 +88,11 @@

};
function wrapCoreMiddleware(mw, options) {
const match = pathMatching(options);
const fn = function* (next) {
if (!match(this)) return yield next;
yield mw.call(this, next);
};
fn._name = mw._name + 'coreMiddlewareWrapper';
return fn;
}

3

package.json
{
"name": "egg-core",
"version": "1.1.0",
"version": "1.2.0",
"description": "A core Pluggable framework based on koa",

@@ -52,2 +52,3 @@ "main": "index.js",

"egg-logger": "^1.4.0",
"egg-path-matching": "^1.0.0",
"extend": "^3.0.0",

@@ -54,0 +55,0 @@ "globby": "^6.1.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc