Comparing version 1.3.0 to 2.0.0
31
index.js
@@ -48,22 +48,23 @@ | ||
return function *(upstream){ | ||
var prev = this.path; | ||
return function (ctx, upstream){ | ||
var prev = ctx.path; | ||
var newPath = match(prev); | ||
debug('mount %s %s -> %s', prefix, name, newPath); | ||
if (!newPath) return yield* upstream; | ||
if (!newPath) return upstream(); | ||
this.mountPath = prefix; | ||
this.path = newPath; | ||
debug('enter %s -> %s', prev, this.path); | ||
ctx.mountPath = prefix; | ||
ctx.path = newPath; | ||
debug('enter %s -> %s', prev, ctx.path); | ||
yield* downstream.call(this, function *(){ | ||
this.path = prev; | ||
yield* upstream; | ||
this.path = newPath; | ||
}.call(this)); | ||
return Promise.resolve(downstream(ctx, () => { | ||
ctx.path = prev; | ||
return upstream().then(() => { | ||
ctx.path = newPath; | ||
}); | ||
})).then(() => { | ||
debug('leave %s -> %s', prev, ctx.path); | ||
ctx.path = prev; | ||
}); | ||
}; | ||
debug('leave %s -> %s', prev, this.path); | ||
this.path = prev; | ||
} | ||
/** | ||
@@ -70,0 +71,0 @@ * Check if `prefix` satisfies a `path`. |
@@ -5,3 +5,3 @@ { | ||
"repository": "koajs/mount", | ||
"version": "1.3.0", | ||
"version": "2.0.0", | ||
"keywords": [ | ||
@@ -17,15 +17,21 @@ "koa", | ||
"devDependencies": { | ||
"koa": "latest", | ||
"should": "^3.0.0", | ||
"mocha": "^1.12.1", | ||
"supertest": "~0.10.0" | ||
"babel-cli": "6", | ||
"babel-core": "6", | ||
"babel-plugin-transform-async-to-generator": "6", | ||
"istanbul": "0", | ||
"koa": "^2.0.0-alpha.3", | ||
"mocha": "2", | ||
"should": "8", | ||
"supertest": "1" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"koa-compose": "^2.2.0", | ||
"debug": "*" | ||
"debug": "*", | ||
"koa-compose": "^3.0.0" | ||
}, | ||
"scripts": { | ||
"test": "make test" | ||
"test": "NODE_ENV=test mocha --require babel-core/register --reporter spec", | ||
"test-cov": "NODE_ENV=test node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --require babel-core/register", | ||
"test-travis": "NODE_ENV=test node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- --require babel-core/register" | ||
} | ||
} |
# koa-mount | ||
Mount other Koa applications as middleware. The `path` passed to `mount()` is stripped | ||
from the URL temporarily until the stack unwinds. This is useful for creating entire | ||
from the URL temporarily until the stack unwinds. This is useful for creating entire | ||
apps or middleware that will function correctly regardless of which path segment(s) | ||
@@ -27,11 +27,11 @@ they should operate on. | ||
var mount = require('koa-mount'); | ||
var koa = require('koa'); | ||
var Koa = require('koa'); | ||
// hello | ||
var a = koa(); | ||
var a = new Koa(); | ||
a.use(function *(next){ | ||
yield next; | ||
this.body = 'Hello'; | ||
a.use(async function (ctx, next){ | ||
await next(); | ||
ctx.body = 'Hello'; | ||
}); | ||
@@ -41,7 +41,7 @@ | ||
var b = koa(); | ||
var b = new Koa(); | ||
b.use(function *(next){ | ||
yield next; | ||
this.body = 'World'; | ||
b.use(async function (ctx, next){ | ||
await next(); | ||
ctx.body = 'World'; | ||
}); | ||
@@ -51,3 +51,3 @@ | ||
var app = koa(); | ||
var app = new Koa(); | ||
@@ -81,15 +81,15 @@ app.use(mount('/hello', a)); | ||
var mount = require('koa-mount'); | ||
var koa = require('koa'); | ||
var Koa = require('koa'); | ||
function *hello(next){ | ||
yield next; | ||
this.body = 'Hello'; | ||
async function hello(ctx, next){ | ||
await next(); | ||
ctx.body = 'Hello'; | ||
} | ||
function *world(next){ | ||
yield next; | ||
this.body = 'World'; | ||
async function world(ctx, next){ | ||
await next(); | ||
ctx.body = 'World'; | ||
} | ||
var app = koa(); | ||
var app = new Koa(); | ||
@@ -96,0 +96,0 @@ app.use(mount('/hello', hello)); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6254
4
77
8
1
+ Addedany-promise@1.3.0(transitive)
+ Addedkoa-compose@3.2.1(transitive)
- Removedkoa-compose@2.5.1(transitive)
Updatedkoa-compose@^3.0.0