mount icon indicating copy to clipboard operation
mount copied to clipboard

Add support to preserve app context on mounted Koa app

Open lbdremy opened this issue 7 years ago • 6 comments

lbdremy avatar May 23 '17 13:05 lbdremy

can you describe what the problem is?

jonathanong avatar Jun 18 '17 02:06 jonathanong

I think this PR can resolve the problem: mount app use signed cookies will catch error.

ps:

  1. mounted app.keys ignored
  2. https://github.com/koajs/koa/issues/203

rdshoep avatar Jul 28 '17 15:07 rdshoep

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 ?

lbdremy avatar Jul 28 '17 16:07 lbdremy

I have forked the repo, and use preserve instead of preserveContext.

https://github.com/smartmiting/koa-mount/tree/preserve

It supports:

  1. preserved context
  2. preserved app props(subdomainOffset, keys for cookies)

If you agree, I will make a new PR.

rdshoep avatar Aug 31 '17 06:08 rdshoep

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

z-vr avatar Sep 27 '17 12:09 z-vr

Has this PR aged like a fine whisky? 🥃

lvl99 avatar Apr 29 '19 17:04 lvl99