Commit fb8f1174a587bb456d542734ef3fda5f21e4d8b2

Authored by Geoffrey PREUD'HOMME
1 parent 07298877

Utilisation de mongodb pour stocker les sessions

Showing 3 changed files with 8 additions and 6 deletions   Show diff stats
app/routes/ApiRtes.js
... ... @@ -4,12 +4,16 @@ var DecryptServ = require('../services/DecryptServ');
4 4 var ConvsServ = require('../services/ConvsServ');
5 5 var MessServ = require('../services/MessServ');
6 6 var fs = require('fs');
  7 +var mongoose = require('mongoose');
7 8 var express = require('express');
8 9 var session = require('express-session');
9 10 var MongoStore = require('connect-mongo')(session);
10 11  
11 12 var api = express();
12 13  
  14 +// Connection à la BDD
  15 +mongoose.connect(require('../../config/db').url);
  16 +
13 17 // Authentication
14 18 reqAuth = function () {
15 19 return function (req, res, next) {
... ... @@ -96,7 +100,9 @@ sessionData = function (session, cb) {
96 100 };
97 101  
98 102 api.use(session({
99   - // TODO Session store https://github.com/expressjs/session#compatible-session-stores
  103 + store: new MongoStore({
  104 + mongooseConnection: mongoose.connection
  105 + }),
100 106 name: 'membreCool',
101 107 resave: false,
102 108 saveUninitialized: true,
... ...
package.json
... ... @@ -5,6 +5,7 @@
5 5 "dependencies": {
6 6 "async": "^0.9.0",
7 7 "body-parser": "^1.12.2",
  8 + "connect-mongo": "^0.8.0",
8 9 "cookie-parser": "^1.3.4",
9 10 "express": "^4.12.3",
10 11 "express-http-proxy": "^0.5.0",
... ...
server.js
1 1 // Modules ====================================================================
2 2 var express = require('express');
3   -var mongoose = require('mongoose');
4 3 var bodyParser = require('body-parser');
5 4  
6 5 // Application ================================================================
... ... @@ -9,10 +8,6 @@ var app = express();
9 8 var config = require('./config/config.js');
10 9 var port = process.env.PORT || config.port;
11 10  
12   -// Connection à la BDD
13   -var db = require('./config/db');
14   -mongoose.connect(db.url);
15   -
16 11 // Tricks
17 12 app.use(bodyParser.json());
18 13 app.use(bodyParser.urlencoded({
... ...