@joyu/egg-session-mongo 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Alibaba Group Holding Limited and other contributors.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # egg-session-mongo
2
+
3
+ [![NPM version][npm-image]][npm-url]
4
+ [![build status][travis-image]][travis-url]
5
+ [![Test coverage][codecov-image]][codecov-url]
6
+ [![David deps][david-image]][david-url]
7
+ [![Known Vulnerabilities][snyk-image]][snyk-url]
8
+ [![npm download][download-image]][download-url]
9
+
10
+ [npm-image]: https://img.shields.io/npm/v/egg-session-mongo.svg?style=flat-square
11
+ [npm-url]: https://npmjs.org/package/egg-session-mongo
12
+ [travis-image]: https://img.shields.io/travis/Mitscherlich/egg-session-mongo.svg?style=flat-square
13
+ [travis-url]: https://travis-ci.org/Mitscherlich/egg-session-mongo
14
+ [codecov-image]: https://img.shields.io/codecov/c/github/Mitscherlich/egg-session-mongo.svg?style=flat-square
15
+ [codecov-url]: https://codecov.io/github/Mitscherlich/egg-session-mongo?branch=master
16
+ [david-image]: https://img.shields.io/david/Mitscherlich/egg-session-mongo.svg?style=flat-square
17
+ [david-url]: https://david-dm.org/Mitscherlich/egg-session-mongo
18
+ [snyk-image]: https://snyk.io/test/npm/egg-session-mongo/badge.svg?style=flat-square
19
+ [snyk-url]: https://snyk.io/test/npm/egg-session-mongo
20
+ [download-image]: https://img.shields.io/npm/dm/egg-session-mongo.svg?style=flat-square
21
+ [download-url]: https://npmjs.org/package/egg-session-mongo
22
+
23
+ A session extension for store session in MongoDB.
24
+
25
+ see Chinese version: [中文](README.zh_CN.md)
26
+
27
+ ## Install
28
+
29
+ ```bash
30
+ $ npm i egg-session-mongo --save
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ```js
36
+ // {app_root}/config/plugin.js
37
+ exports.sessionMongo = {
38
+ enable: true,
39
+ package: 'egg-session-mongo',
40
+ };
41
+ ```
42
+
43
+ or you can overwrite you `MongoStore` options in `app.js`.
44
+
45
+ ```js
46
+ // {app_root}/app.js
47
+ module.exports = app => {
48
+ const MongoStore = require('egg-session-mongo')(app);
49
+
50
+ app.beforeStart(async () => {
51
+ app.sessionStore = new MongStore(/* options */);
52
+ });
53
+ };
54
+ ```
55
+
56
+ see [app.js](app.js) for more detail.
57
+
58
+ ## Configuration
59
+
60
+ ```js
61
+ // {app_root}/config/config.default.js
62
+ exports.sessionMongo = {
63
+ url: 'mongodb://127.0.0.1/test'
64
+ };
65
+ ```
66
+
67
+ see [config/config.example.js](config/config.example.js) for more detail.
68
+
69
+ ## Questions & Suggestions
70
+
71
+ Please open an issue [here](https://github.com/eggjs/egg/issues).
72
+ or open an issue just at this repo's [issue](https://github.com/Mitscherlich/egg-session-mongo/issues) for more timely reply
73
+
74
+ ## License
75
+
76
+ [MIT](LICENSE)
@@ -0,0 +1,66 @@
1
+ # egg-session-mongo
2
+
3
+ [![NPM version][npm-image]][npm-url]
4
+ [![build status][travis-image]][travis-url]
5
+ [![Test coverage][codecov-image]][codecov-url]
6
+ [![David deps][david-image]][david-url]
7
+ [![Known Vulnerabilities][snyk-image]][snyk-url]
8
+ [![npm download][download-image]][download-url]
9
+
10
+ [npm-image]: https://img.shields.io/npm/v/egg-session-mongo.svg?style=flat-square
11
+ [npm-url]: https://npmjs.org/package/egg-session-mongo
12
+ [travis-image]: https://img.shields.io/travis/Mitscherlich/egg-session-mongo.svg?style=flat-square
13
+ [travis-url]: https://travis-ci.org/Mitscherlich/egg-session-mongo
14
+ [codecov-image]: https://img.shields.io/codecov/c/github/Mitscherlich/egg-session-mongo.svg?style=flat-square
15
+ [codecov-url]: https://codecov.io/github/Mitscherlich/egg-session-mongo?branch=master
16
+ [david-image]: https://img.shields.io/david/Mitscherlich/egg-session-mongo.svg?style=flat-square
17
+ [david-url]: https://david-dm.org/Mitscherlich/egg-session-mongo
18
+ [snyk-image]: https://snyk.io/test/npm/egg-session-mongo/badge.svg?style=flat-square
19
+ [snyk-url]: https://snyk.io/test/npm/egg-session-mongo
20
+ [download-image]: https://img.shields.io/npm/dm/egg-session-mongo.svg?style=flat-square
21
+ [download-url]: https://npmjs.org/package/egg-session-mongo
22
+
23
+ 基于 [`connect-mongo`](https://github.com/jdesboeufs/connect-mongo) 的 [`egg-session`](https://github.com/eggjs/egg-session) 外部存储插件,将 `session` 存储在 `MongoDB` 中。支持 `connect-mongo` 所有配置。
24
+
25
+ ## 依赖说明
26
+
27
+ ### 依赖的 egg 版本
28
+
29
+ egg-session-mongo 版本 | egg 1.x
30
+ --- | ---
31
+ 1.x | 😁
32
+ 0.x | ❌
33
+
34
+ ## 开启插件
35
+
36
+ ```js
37
+ // {app_root}/config/plugin.js
38
+ exports.sessionMongo = {
39
+ enable: true,
40
+ package: 'egg-session-mongo',
41
+ };
42
+ ```
43
+
44
+ ## 使用场景
45
+
46
+ 支持在 `egg.js` 中扩展插件 `egg-session`,将 session 数据存储在外部 `MongoDB` 数据库中。基于 `connect-mongo` 开发,兼容其所有的配置选项,基于 `native-node-mongo` 原生模块链接 `MongoDB` 链接数据库,可以复用已有的 `mongoose` 或 `mongodb` 数据库连接。
47
+
48
+ ## 详细配置
49
+
50
+ 请到 [config/config.default.js](config/config.default.js) 查看详细配置项说明。
51
+
52
+ ## 单元测试
53
+
54
+ ```bash
55
+ $ git clone --depth 1 https://github.com/Mitscherlich/egg-session-mongo && cd egg-session-mongo
56
+ $ npm i --save
57
+ $ npm run test
58
+ ```
59
+
60
+ ## 提问交流
61
+
62
+ 请到 [egg issues](https://github.com/eggjs/egg/issues) 异步交流。
63
+
64
+ ## License
65
+
66
+ [MIT](LICENSE)
package/app.js ADDED
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ module.exports = app => {
4
+ const MongoStore = require('koa2-session-mongo');
5
+ const options = app.config.sessionMongo;
6
+
7
+ app.beforeStart(async () => {
8
+ app.sessionStore = new MongoStore(options);
9
+ });
10
+ };
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * egg-session-mongo default config
5
+ */
6
+ exports.sessionMongo = {
7
+ };
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * egg-session-mongo default config
5
+ * @member Config#sessionMongo
6
+ * @property {string} [url='mongodb://127.0.0.1/test'] - MongoDB server url
7
+ * @property {string|Object} [db='test'] - `String` for a new connection or a exist mongoClient will be reuse if is an object
8
+ * @property {string} [collection='sessions'] - Session store collection name
9
+ * @property {Object} [mongooseConnection] - Re-use existing or upcoming mongoose connection
10
+ * @property {number} [ttl=1209600] - Session expire time
11
+ */
12
+ exports.sessionMongo = {
13
+ url: 'mongodb://127.0.0.1',
14
+ db: 'test',
15
+ collection: 'sessions',
16
+ mongooseConnection: null, // uncomment this to re-use existing or upcoming mongoose connection
17
+ ttl: 14 * 24 * 60 * 60, // = 14 days. Default
18
+ };
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@joyu/egg-session-mongo",
3
+ "version": "2.0.3",
4
+ "description": "MongoDB store for egg session. based on `connect-mongo`.",
5
+ "main": "index.js",
6
+ "eggPlugin": {
7
+ "name": "sessionMongo"
8
+ },
9
+ "keywords": [
10
+ "egg",
11
+ "eggPlugin",
12
+ "egg-plugin",
13
+ "session",
14
+ "mongo",
15
+ "MongoDB"
16
+ ],
17
+ "dependencies": {
18
+ "koa2-session-mongo": "^0.1.0",
19
+ "mongodb": "^7.0.0"
20
+ },
21
+ "devDependencies": {
22
+ "autod": "3.1.2",
23
+ "autod-egg": "1.1.0",
24
+ "egg": "3.30.1",
25
+ "egg-bin": "6.13.0",
26
+ "egg-ci": "2.2.0",
27
+ "egg-mock": "5.15.1",
28
+ "eslint": "9.32.0",
29
+ "eslint-config-egg": "14.1.0",
30
+ "mongoose": "8.13.0",
31
+ "mz-modules": "2.1.0",
32
+ "supertest": "7.1.0",
33
+ "webstorm-disable-index": "1.2.0"
34
+ },
35
+ "engines": {
36
+ "node": ">=8.0.0"
37
+ },
38
+ "scripts": {
39
+ "test": "npm run lint -- --fix && egg-bin pkgfiles && npm run test-local",
40
+ "test-local": "egg-bin test",
41
+ "cov": "egg-bin cov",
42
+ "lint": "eslint .",
43
+ "ci": "egg-bin pkgfiles --check && npm run lint && npm run cov",
44
+ "pkgfiles": "egg-bin pkgfiles",
45
+ "autod": "autod"
46
+ },
47
+ "files": [
48
+ "config",
49
+ "app.js"
50
+ ],
51
+ "ci": {
52
+ "version": "8, 9"
53
+ },
54
+ "publishConfig": {
55
+ "registry": "https://registry.npmjs.org",
56
+ "access": "public"
57
+ },
58
+ "repository": "https://github.com/joyutech/egg-session-mongo",
59
+ "bugs": "https://github.com/joyutech/egg-session-mongo/issues",
60
+ "homepage": "https://github.com/joyutech/egg-session-mongo#readme",
61
+ "author": "Joyu Team",
62
+ "license": "MIT"
63
+ }