egg-session-mongo
Advanced tools
Comparing version 0.0.1 to 1.0.0
'use strict'; | ||
module.exports = app => { | ||
app.sessionStore = require('./lib/session')(app); | ||
const MongoStore = require('./lib/session')(app); | ||
const options = app.config.sessionMongo; | ||
app.beforeStart(async () => { | ||
app.sessionStore = new MongoStore(options); | ||
}); | ||
}; |
@@ -54,7 +54,7 @@ 'use strict'; | ||
if (options.fallbackMemory === true) { | ||
return MemoryStore; | ||
return MemoryStore.prototype; | ||
} | ||
class MongoStore extends EventEmitter { | ||
constructor(app) { | ||
constructor(options) { | ||
super(); | ||
@@ -71,3 +71,2 @@ | ||
this.options = options; | ||
this.app = app; | ||
@@ -209,10 +208,4 @@ this.changeState('init'); | ||
let s; | ||
const s = { _id: this.computeStorageId(sid), session: this.transformFunctions.serialize(session) }; | ||
try { | ||
s = { _id: this.computeStorageId(sid), session: this.transformFunctions.serialize(session) }; | ||
} catch (err) { | ||
return this.app.coreLogger.error(err); | ||
} | ||
if (session && session._expire) { | ||
@@ -219,0 +212,0 @@ s.expires = new Date(session._expire); |
{ | ||
"name": "egg-session-mongo", | ||
"version": "0.0.1", | ||
"description": "mongodb store for egg session", | ||
"version": "1.0.0", | ||
"description": "mongodb store for egg session. based on `connect-mongo`", | ||
"eggPlugin": { | ||
@@ -43,5 +43,6 @@ "name": "sessionMongo" | ||
"files": [ | ||
"index.js", | ||
"lib", | ||
"config", | ||
"app.js", | ||
"lib" | ||
"app.js" | ||
], | ||
@@ -53,3 +54,3 @@ "ci": { | ||
"type": "git", | ||
"url": "git+https://github.com/eggjs/egg-session-mongo.git" | ||
"url": "git+https://github.com/Mitscherlich/egg-session-mongo.git" | ||
}, | ||
@@ -59,5 +60,5 @@ "bugs": { | ||
}, | ||
"homepage": "https://github.com/eggjs/egg-session-mongo#readme", | ||
"homepage": "https://github.com/Mitscherlich/egg-session-mongo#readme", | ||
"author": "Mitscherlich", | ||
"license": "MIT" | ||
} |
@@ -12,8 +12,8 @@ # egg-session-mongo | ||
[npm-url]: https://npmjs.org/package/egg-session-mongo | ||
[travis-image]: https://img.shields.io/travis/eggjs/egg-session-mongo.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/eggjs/egg-session-mongo | ||
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-session-mongo.svg?style=flat-square | ||
[codecov-url]: https://codecov.io/github/eggjs/egg-session-mongo?branch=master | ||
[david-image]: https://img.shields.io/david/eggjs/egg-session-mongo.svg?style=flat-square | ||
[david-url]: https://david-dm.org/eggjs/egg-session-mongo | ||
[travis-image]: https://img.shields.io/travis/Mitscherlich/egg-session-mongo.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/Mitscherlich/egg-session-mongo | ||
[codecov-image]: https://img.shields.io/codecov/c/github/Mitscherlich/egg-session-mongo.svg?style=flat-square | ||
[codecov-url]: https://codecov.io/github/Mitscherlich/egg-session-mongo?branch=master | ||
[david-image]: https://img.shields.io/david/Mitscherlich/egg-session-mongo.svg?style=flat-square | ||
[david-url]: https://david-dm.org/Mitscherlich/egg-session-mongo | ||
[snyk-image]: https://snyk.io/test/npm/egg-session-mongo/badge.svg?style=flat-square | ||
@@ -26,6 +26,8 @@ [snyk-url]: https://snyk.io/test/npm/egg-session-mongo | ||
see Chinese version: [中文](README.zh_CN.md) | ||
## Install | ||
```bash | ||
$ cd /path/to/your/project/node_modules && git clone --depth 1 https://github.com/Mitscherlich/egg-session-mongo | ||
$ npm i egg-session-mongo --save | ||
``` | ||
@@ -43,18 +45,23 @@ | ||
or you can overwrite you `MongoStore` options in `app.js` | ||
```js | ||
// {app_root}/app.js | ||
module.exports = app => { | ||
const MongoStore = require('egg-session-mongo')(app); | ||
app.beforeStart(async () => { | ||
app.sessionStore = new MongStore(/* options */); | ||
}); | ||
}; | ||
``` | ||
see [app.js](app.js) for more detail. | ||
## Configuration | ||
```js | ||
/** | ||
* egg-session-mongo default config | ||
* @member Config#sessionMongo | ||
* @property {string} [url='mongodb://127.0.0.1/test'] - MongoDB server url | ||
* @property {string} [collection='sessions'] - Session store collection name | ||
* @property {Object} [mongooseConnection] - Re-use existing or upcoming mongoose connection | ||
* @property {number} [ttl=1209600] - Session expire time | ||
*/ | ||
// {app_root}/config/config.default.js | ||
exports.sessionMongo = { | ||
url: 'mongodb://127.0.0.1/test', | ||
collection: 'sessions', | ||
mongooseConnection: null, // uncomment this to re-use existing or upcoming mongoose connection | ||
ttl: 14 * 24 * 60 * 60, // = 14 days. Default | ||
url: 'mongodb://127.0.0.1/test' | ||
}; | ||
@@ -61,0 +68,0 @@ ``` |
@@ -12,8 +12,8 @@ # egg-session-mongo | ||
[npm-url]: https://npmjs.org/package/egg-session-mongo | ||
[travis-image]: https://img.shields.io/travis/eggjs/egg-session-mongo.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/eggjs/egg-session-mongo | ||
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-session-mongo.svg?style=flat-square | ||
[codecov-url]: https://codecov.io/github/eggjs/egg-session-mongo?branch=master | ||
[david-image]: https://img.shields.io/david/eggjs/egg-session-mongo.svg?style=flat-square | ||
[david-url]: https://david-dm.org/eggjs/egg-session-mongo | ||
[travis-image]: https://img.shields.io/travis/Mitscherlich/egg-session-mongo.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/Mitscherlich/egg-session-mongo | ||
[codecov-image]: https://img.shields.io/codecov/c/github/Mitscherlich/egg-session-mongo.svg?style=flat-square | ||
[codecov-url]: https://codecov.io/github/Mitscherlich/egg-session-mongo?branch=master | ||
[david-image]: https://img.shields.io/david/Mitscherlich/egg-session-mongo.svg?style=flat-square | ||
[david-url]: https://david-dm.org/Mitscherlich/egg-session-mongo | ||
[snyk-image]: https://snyk.io/test/npm/egg-session-mongo/badge.svg?style=flat-square | ||
@@ -38,3 +38,3 @@ [snyk-url]: https://snyk.io/test/npm/egg-session-mongo | ||
```js | ||
// config/plugin.js | ||
// {app_root}/config/plugin.js | ||
exports.sessionMongo = { | ||
@@ -58,2 +58,3 @@ enable: true, | ||
$ git clone --depth 1 https://github.com/Mitscherlich/egg-session-mongo && cd egg-session-mongo | ||
$ npm i --save | ||
$ npm run test | ||
@@ -60,0 +61,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
9
0
76
21866