Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use express ttl #12

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# bedrock-session-mongodb ChangeLog

## 4.2.0 -

### Changed
- `config.session-mongodb.ttl` is now a computed property.
- `config.session-mongodb.ttl` is now computed from config.express.session.ttl.

## 4.1.0 - 2020-07-07

### Changed
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ bedrock.start();

For documentation on configuration, see [config.js](./lib/config.js).

`config.session-mongodb.ttl` is a computed property that converts
`config.express.session.ttl` to seconds. In order to change the ttl for sessions you will
now need to change the `config.express.session.ttl` using milliseconds.

[bedrock]: https://github.com/digitalbazaar/bedrock
[bedrock-express]: https://github.com/digitalbazaar/bedrock-express
Expand Down
20 changes: 16 additions & 4 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@
*/
'use strict';

const {config} = require('bedrock');

const {config, util} = require('bedrock');
const cc = util.config.main.computer();
config['session-mongodb'] = {
collection: 'session',
// timeout is in seconds (time for session to live on the server)
ttl: 60 * 30
};

// MongoStore ttl defaults to thirtyMinutes expressed in seconds.
const thirtyMinutes = 60 * 30;

// timeout is in seconds (time for session to live on the server)
cc('session-mongodb.ttl', () => {
if(config.express && config.express.session) {
// express session ttl is in milliseconds
const {ttl = thirtyMinutes * 1000} = config.express.session;
// round down to ensure session doesn't live beyond configured value
return Math.floor(ttl / 1000);
}
return thirtyMinutes;
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"peerDependencies": {
"bedrock": "1.0.0 - 3.x",
"bedrock-express": "2.0.3 - 3.x",
"bedrock-express": "2.0.3 - 4.x",
"bedrock-mongodb": "^7.1.0"
},
"directories": {
Expand Down