sesstion 设置之后没有同步到cookie里面
- Dominant language
- TypeScript
- Stars
- 908
- Forks
- 115
- PR merge metrics
- No merged PRs in 30d
Description
所以session无法记录
非常神奇的一个问题。
我的koa-router配置文件如下

```js
// index.js
const Api = require('./api.js');
const Upload = require('./upload');
const Auth = require('./auth');
const router = require('koa-router')();
const koaBody = require('koa-body');
router
.get('/api', Api)
.all('/auth', Auth)
.post('/upload', koaBody({ multipart: true }), Upload)
.get('/test1',function(ctx,next){
ctx.body = '123'
ctx.session.hee = ctx.session.hee+1 || 0;
})
// .get('/test2',function(ctx,next){
// ctx.body = ctx.session.hee
// })
module.exports = router;
```
```js
const axios = require('axios');
const Api = async function(ctx,next) {
axios({
url: 'http://192.168.1.14:8080/daocheng/a/mall/105293660609/get_goods_list_shop',
method: "post",
params: {
order: '',
nopage: 1,
corp_pri: 0,
pageSize: 15,
goods_name: '',
_extfn: 'get_shop_goods_by_type_list2',
id: '9ae4ca9d069547c19deb61f010518ec0',
},
headers: {
"Cookie": ctx.session.javaCookie || null,
}
})
.then(async res => {
if(!ctx.session.javaCookie) {
ctx.session.javaCookie = res.headers['set-cookie'] ? res.headers['set-cookie'] : ''
}
console.log(res.headers['set-cookie']);
console.log('正确')
// console.log(response.data)
ctx.session.hee = ctx.session.hee+1 || 0;
console.log(ctx.session);
await next();
})
.catch(error => {
console.log('错误')
console.log(error.response)
});
};
module.exports = Api;
```

非常神奇,我在axios里面修改ctx.session.hee居然不会被保存
但是在下面这个index.js这个地方修改ctx.session.hee又是可以同步cookie。

Contributor guide
Research direction
Review the session updates in index.js and api.js, especially the axios callback where ctx.session.hee and ctx.session.javaCookie are changed. Trace how the request lifecycle saves session state after the callback, then reproduce the difference between /test1 and Api and add a regression test showing the expected persistence.
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
- Needs clarification
- Newbie friendliness
- 25/100