Skip to content

Commit

Permalink
enabled force save
Browse files Browse the repository at this point in the history
  • Loading branch information
calidion committed Mar 2, 2021
1 parent a2c7e80 commit d7010a7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aex/session",
"version": "0.2.0",
"version": "0.2.2",
"description": "aex session for basic http request",
"license": "MIT",
"repository": "",
Expand Down
5 changes: 4 additions & 1 deletion src/session/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class Cookie extends Session {
public async parse(req: IncomingMessage, res: ServerResponse, scope?: any) {
const header = req.headers['cookie'] || '';
const parsed: any = cookie.parse(header);
let saved = false;
let id: string;
if (!scope) {
scope = req;
Expand Down Expand Up @@ -55,10 +56,12 @@ export class Cookie extends Session {
}

scope.session.save = async () => {
saved = true;
await this.store.set(id, scope.session);
}
};
// store all session data into store after the request
setImmediate(async () => {
if (saved) return;
await this.store.set(id, scope.session);
});
}
Expand Down

0 comments on commit d7010a7

Please sign in to comment.