koajs / koajs/session

koa session does not work when used in a middleware app

Open
#33 7 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
908
Forks
115
PR merge metrics
No merged PRs in 30d

Description

I am using the vhost middleware with koa-session. Since koa-session 2.0.0 is was possible to use it in a subapp. Since 3.0.0 this does not work anymore. Example:

var session = require('./');
var koa = require('koa');
var compose = require('koa-compose');
var app = koa();

app.keys = ['some secret hurr'];

app.use(session(app));

app.use(function* (next){
  if ('/favicon.ico' == this.path) return;
  var n = this.session.views || 0;
  this.session.views = ++n;
  this.body = n + ' views';
});

var server = koa();
server.use(compose(app.middleware));
server.listen(3000);

console.log('listening on port 3000');

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the koa-session 3.0.0 middleware entry point and reproduce the issue using the example with koa, koa-compose, and vhost-style subapp composition. Trace why session setup differs from 2.0.0, then verify that the same session behavior works when the app middleware is composed into the parent server.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.