mount
mount copied to clipboard
Add support to preserve app context on mounted Koa app
can you describe what the problem is?
I think this PR can resolve the problem: mount app use signed cookies will catch error.
ps:
Hi,
I have done this change to keep the context given to the app, not the context of the app on which it is mounted.
const app = new Koa();
app.context.config = { hello: 'sir' };
app.use((ctx) => {
ctx.config // is set to { hello: 'sir'} and not { hi: 'sir'};
});
const root = new Koa();
root.context.config = { hi: 'sir'};
root.mount('/api', app, true);
maybe a more explicit api for the options will be nice, something like
root.mount('/api',app, { preserveContext: true }); // keepContext ?
I have forked the repo, and use preserve instead of preserveContext.
https://github.com/smartmiting/koa-mount/tree/preserve
It supports:
- preserved context
- preserved app props(subdomainOffset, keys for cookies)
If you agree, I will make a new PR.
Thanks @lbdremy, this is a very useful feature (could you possibly fix the linting problem which makes CI fail? @jonathanong it'd be great if you could merge and release this PR please.
If anyone comes across this issue, here's a fork: https://www.npmjs.com/package/@zavr/koa-mount
Has this PR aged like a fine whisky? 🥃