Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Nostradamos opened this issue Oct 27, 2017 · 4 comments
Open

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

Nostradamos opened this issue Oct 27, 2017 · 4 comments

Comments

@Nostradamos
Copy link

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

@Yugloocamai
Copy link

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

@jbemmel
Copy link

jbemmel commented Nov 1, 2019

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)

@pke
Copy link

pke commented Nov 27, 2019

@jbemmel can you provide a PR?

@jbemmel
Copy link

jbemmel commented Nov 27, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants