mount icon indicating copy to clipboard operation
mount copied to clipboard

mounted app.context doesn't get applied to parent app

Open Nostradamos opened this issue 8 years ago • 4 comments

Example:

const mount = require('koa-mount');
const Koa = require('koa');

const a = new Koa();
a.context.test = "hallo";

a.use(async function (ctx, next){
    ctx.body = "test:" + ctx.test;
    return next();
});

// app

const app = new Koa();

app.use(mount('/hello', a));
app.listen(3000)
a.listen(3001);

http://localhost:3000/hello results in test:hallo http://localhost:3001/hello results in test:undefined

Nostradamos avatar Oct 27 '17 22:10 Nostradamos

Having this exact issue. Middleware should be configurable to be hierarchical.

Yugloocamai avatar Sep 17 '18 20:09 Yugloocamai

It's more than just app.context, mounting bypasses all context initialization performed at https://github.com/koajs/koa/blob/master/lib/application.js#L175

Try sending a request over https:// to a mounted app, and checking ctxt.request.secure

This module fundamentally breaks Koa, it is incompatible. When mounting Koa applications https://github.com/koajs/mount#mounting-applications, it should use callback() to make sure the correct processing happens (at https://github.com/koajs/mount/blob/master/index.js#L36)

jbemmel avatar Nov 01 '19 00:11 jbemmel

@jbemmel can you provide a PR?

pke avatar Nov 27 '19 09:11 pke

Hi Philipp, In my opinion the problem is with Koa - it has a complex implicit structure that is non-intuitive, and module writers easily get things wrong. I have decided that Koa is not something I want to invest in

jbemmel avatar Nov 27 '19 14:11 jbemmel