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,12 +4,16 @@ var DecryptServ = require('../services/DecryptServ');
4 var ConvsServ = require('../services/ConvsServ'); 4 var ConvsServ = require('../services/ConvsServ');
5 var MessServ = require('../services/MessServ'); 5 var MessServ = require('../services/MessServ');
6 var fs = require('fs'); 6 var fs = require('fs');
  7 +var mongoose = require('mongoose');
7 var express = require('express'); 8 var express = require('express');
8 var session = require('express-session'); 9 var session = require('express-session');
9 var MongoStore = require('connect-mongo')(session); 10 var MongoStore = require('connect-mongo')(session);
10 11
11 var api = express(); 12 var api = express();
12 13
  14 +// Connection à la BDD
  15 +mongoose.connect(require('../../config/db').url);
  16 +
13 // Authentication 17 // Authentication
14 reqAuth = function () { 18 reqAuth = function () {
15 return function (req, res, next) { 19 return function (req, res, next) {
@@ -96,7 +100,9 @@ sessionData = function (session, cb) { @@ -96,7 +100,9 @@ sessionData = function (session, cb) {
96 }; 100 };
97 101
98 api.use(session({ 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 name: 'membreCool', 106 name: 'membreCool',
101 resave: false, 107 resave: false,
102 saveUninitialized: true, 108 saveUninitialized: true,
@@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
5 "dependencies": { 5 "dependencies": {
6 "async": "^0.9.0", 6 "async": "^0.9.0",
7 "body-parser": "^1.12.2", 7 "body-parser": "^1.12.2",
  8 + "connect-mongo": "^0.8.0",
8 "cookie-parser": "^1.3.4", 9 "cookie-parser": "^1.3.4",
9 "express": "^4.12.3", 10 "express": "^4.12.3",
10 "express-http-proxy": "^0.5.0", 11 "express-http-proxy": "^0.5.0",
1 // Modules ==================================================================== 1 // Modules ====================================================================
2 var express = require('express'); 2 var express = require('express');
3 -var mongoose = require('mongoose');  
4 var bodyParser = require('body-parser'); 3 var bodyParser = require('body-parser');
5 4
6 // Application ================================================================ 5 // Application ================================================================
@@ -9,10 +8,6 @@ var app = express(); @@ -9,10 +8,6 @@ var app = express();
9 var config = require('./config/config.js'); 8 var config = require('./config/config.js');
10 var port = process.env.PORT || config.port; 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 // Tricks 11 // Tricks
17 app.use(bodyParser.json()); 12 app.use(bodyParser.json());
18 app.use(bodyParser.urlencoded({ 13 app.use(bodyParser.urlencoded({